0

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/}
1
  • Question has been updated. Please have a look
    – onkar
    Nov 26, 2012 at 10:07

2 Answers 2

0

Add your image string in your post dictionary:

[dictionnary setObject:imageEncodedString forKey:@"image"];

4
  • but it is not giving me desired result(No jSON object response )
    – onkar
    Nov 26, 2012 at 10:30
  • data must be converted to base64
    – Daij-Djan
    Nov 26, 2012 at 10:34
  • You want to post encoded image to server. With this you are posting your image to server.
    – OnkarK
    Nov 26, 2012 at 10:34
  • @Daij-Djan every thing is done. Data to be sent is ready, butI get no response
    – onkar
    Nov 26, 2012 at 10:35
0

You can use NSMutableDictionary

look this

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.