NsurlConnection non invia dati, ma si collega
-
15-11-2019 - |
Domanda
L'URL è scritto correttamente, l'ho testato nel browser con i dati e mi invia correttamente, ma quando faccio la richiesta, restituisce che ha esito positivo, ma in realtà non scrive i dati.Qualche idea?
- (void)writeAboutMe:(NSString *)about withIcebreaker:(NSString *)icebreaker
{
NSMutableURLRequest *request = [[[NSMutableURLRequest alloc] init] autorelease];
NSString *urlString = [NSString stringWithFormat:@"http://nailorbail.net63.net/submit_about_and_icebreaker.php?username=%@&about=%@&icebreaker=%@",[SignInViewController getUsernameString] ,about,icebreaker];
NSLog(@"%@",urlString);
[request setURL:[NSURL URLWithString:urlString]];
[request setHTTPMethod:@"GET"];
[request setValue:@"application/x-www-form-urlencoded" forHTTPHeaderField:@"Current-Type"];
NSURLConnection *conn = [[NSURLConnection alloc]initWithRequest:request delegate:self];
if(conn)
NSLog(@"Connection Successful");
else
NSLog(@"Connection could not be made");
[conn release];
}
. Soluzione
It could be an encoding issue. What kinds of characters are in getUsernameString
, about
, and icebreaker
? As Maudicus mentioned, you need to handle special characters in the URL yourself.
Try:
urlString = [urlString stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding]
Altri suggerimenti
You have set up an asynchronous connection. Do you implement the NSURLConnection delegate protocol methods? Are any of them being called?
The creation of the connection instance doesn't say anything about it's success.
Check out some tutorials, like this one.
Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow