I am trying to post data to a .NET web-service using the following:
NSString *string = [self encodeToBase64String:profilePic.image];
originalString = string;
string = [string stringByReplacingOccurrencesOfString:@"/"
withString:@"%2F"];
string = [string stringByReplacingOccurrencesOfString:@"+" withString:@"%2B"]; // iOS 7+
NSLog(@"Original String: %@", originalString);
sentString = string;
NSString *post = [[NSString stringWithFormat:@"firstName=%@&lastname=%@&password=%@&email=%@&bio=%@&activeDeviceId=%@&latitude=%f&longitude=%f&city=%@&country=%@&countyState=%@&base64=%@", firstName, lastName, password, email, bio, activeDeviceId, latitude, longitude, city, country, countyState, string] stringByAddingPercentEscapesUsingEncoding:NSASCIIStringEncoding];
//NSString *post = [NSString stringWithFormat:@"firstName=%@&lastname=%@&password=%@&email=%@&bio=%@&activeDeviceId=%@&latitude=%f&longitude=%f&city=%@&country=%@&countyState=%@&base64=%@", firstName, lastName, password, email, bio, activeDeviceId, latitude, longitude, city, country, countyState, string];
NSData *postData = [post dataUsingEncoding:NSASCIIStringEncoding allowLossyConversion:NO];
NSString *postLength = [NSString stringWithFormat:@"%d", [postData length]];
NSLog(@"Length: %@", postLength);
NSMutableURLRequest *request = [[NSMutableURLRequest alloc] init];
[request setURL:[NSURL URLWithString:@"http://myservice/service.asmx/Register"]];
[request setHTTPMethod:@"POST"];
[request setValue:postLength forHTTPHeaderField:@"Content-Length"];
[request setValue:@"application/x-www-form-urlencoded" forHTTPHeaderField:@"Content-Type"];
[request setHTTPBody:postData];
[NSURLConnection connectionWithRequest:request delegate:self];
At the moment the web-service is just returning the base64 string it receives prior to decoding (so just the value of the parameter).
Later in my code I parse the returned XML and compare the original base64 string with the one I received from my web-service and they do not match.
I've tried a few different approaches with no luck. Is there something wrong with how I am posting the data?
Aucun commentaire:
Enregistrer un commentaire