http-post request for a long String in iOS

Posted by onkar on Stack Overflow See other posts from Stack Overflow or by onkar
Published on 2012-11-26T09:54:37Z Indexed on 2012/11/26 11:05 UTC
Read the original article Hit count: 303

Filed under:
|
|

I am looking to send a very long String, which is an image that is encoded into a String. I need to send that information using POST method. I have implemented the same in Android using key-value pair, I need to implement the same in iOS using key-value pair. Please help me with useful resources/approach.

EDIT 1

What have I tried

[dictionnary setObject:@"admin"  forKey:@"username"];
[dictionnary setObject:@"123123" forKey:@"password"];

NSError *error = nil;

NSData *jsonData = [NSJSONSerialization dataWithJSONObject:dictionnary
                                                   options:kNilOptions
                                                     error:&error];

NSString *urlString = @"MY CALL URL";

NSURL *url = [NSURL URLWithString:urlString];
NSMutableURLRequest *request = [NSMutableURLRequest requestWithURL:url];
[request setHTTPMethod:@"POST"];

[request setHTTPBody:jsonData];
NSURLResponse *response = NULL;
NSError *requestError = NULL;
NSData *responseData = [NSURLConnection sendSynchronousRequest:request returningResponse:&response error:&requestError];
NSLog(@"response is obtained");

NSString *responseString = [[NSString alloc] initWithData:responseData encoding:NSUTF8StringEncoding] ;
NSLog(@"%@", responseString);

EDIT 2

Error I am getting

Request Error Error Domain=kCFErrorDomainCFNetwork Code=303 "The operation couldn’t be completed. (kCFErrorDomainCFNetwork error 303.)" UserInfo=0x7ba0120 {NSErrorFailingURLKey=http://yahoo.com/, NSErrorFailingURLStringKey=http://yahoo.com/}

© Stack Overflow or respective owner

Related posts about iphone

Related posts about objective-c