/ Published in: Objective C
Expand |
Embed | Plain Text
//prepar request [request setHTTPMethod:@"POST"]; //set headers [request addValue:contentType forHTTPHeaderField: @"Content-Type"]; //create the body [postBody appendData:[[NSString stringWithFormat:@"<xml>"] dataUsingEncoding:NSUTF8StringEncoding]]; [postBody appendData:[[NSString stringWithFormat:@"<yourcode/>"] dataUsingEncoding:NSUTF8StringEncoding]]; [postBody appendData:[[NSString stringWithFormat:@"</xml>"] dataUsingEncoding:NSUTF8StringEncoding]]; //post [request setHTTPBody:postBody]; //get response NSData *responseData = [NSURLConnection sendSynchronousRequest:request returningResponse:&urlResponse error:&error]; NSLog(@"Response Code: %d", [urlResponse statusCode]); if ([urlResponse statusCode] >= 200 && [urlResponse statusCode] < 300) { NSLog(@"Response: %@", result); //here you get the response }
Comments
Subscribe to comments
You need to login to post a comment.

How do you grab this post on you php page when it has no name?
Great post david, works great here, I had a small problem though, with the postBody, in my case I had to replace with something like this:
NSString *formData = [[NSString alloc] initWithFormat:@"", txtUsername.text, txtPass.text];
NSData *postData = [[NSString stringWithFormat:formData] dataUsingEncoding:NSUTF8StringEncoding];
in this way works perfectly fine,
Thanks,
Alex