Note that there are some explanatory texts on larger screens.

plurals
  1. POupload image along with json in ios using multipart/mixed
    primarykey
    data
    text
    <p>I am new to ios webservices ,so i am stuck with a problem for the last 2 to 3 days , I have to send a request to server which has multiple parts like image and json ,I tried to use the multipart/form-data to send my request but for some reason the server was not able to get the request ,can anyone help me to solve this problem </p> <p>The code i am using is </p> <pre><code>NSData *imageData = UIImagePNGRepresentation(img); NSMutableURLRequest *theRequest =[NSMutableURLRequest requestWithURL:theURL]; NSString *boundary = [NSString stringWithFormat:@"---------------------------14737809831466499882746641449"]; NSString *contentType = [NSString stringWithFormat:@"multipart/form-data; boundary=%@", boundary]; [theRequest addValue:contentType forHTTPHeaderField:@"Content-Type"]; [theRequest setHTTPMethod:@"POST"]; NSMutableString *theBody = [[NSMutableString alloc]init]; [theBody appendString:[NSString stringWithFormat:@"\r\n--%@\r\n", boundary]]; [theBody appendString:[NSString stringWithFormat:@"Content-Type: application/json\r\n\r\n"]]; //append The Json string [theBody appendString:myJsonString]; [theBody appendString:[NSString stringWithFormat:@"%@", boundary]]; //this appends the image [theBody appendString:[NSString stringWithFormat:@"Content-Disposition: form-data; name=\"data\"; filename=\"photo\""]]; [theBody appendString:[NSString stringWithFormat:@"Content-Type: image/png\r\n\r\n"]]; [theBody appendString:[NSString stringWithFormat:@"%@",imageData]]; [theBody appendString:[NSString stringWithFormat:@"\r\n--%@\r\n", boundary] ]; [theRequest setHTTPBody:[theBody dataUsingEncoding:NSUTF8StringEncoding]]; </code></pre>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload