Note that there are some explanatory texts on larger screens.

plurals
  1. POObjective C Post Multipart/data Text Error
    primarykey
    data
    text
    <p>I have a problem with an <code>http Post request</code> the situation is follows:</p> <p>I have to send a post request with text and Img here the code:</p> <pre><code>NSMutableURLRequest *eventRequest = [NSMutableURLRequest requestWithURL:_urlRequest cachePolicy:NSURLRequestUseProtocolCachePolicy timeoutInterval:500]; NSString *boundary = @"---------------------------14737809831466499882746641449"; //Set header Http POST [eventRequest setHTTPMethod:@"POST"]; [eventRequest setValue:[NSString stringWithFormat:@"multipart/form-data; boundary=%@", boundary]forHTTPHeaderField:@"Content-Type"]; NSMutableData *body = [NSMutableData data]; [body appendData:[[NSString stringWithFormat:@"--%@\r\n", boundary] dataUsingEncoding:NSUTF8StringEncoding]]; [body appendData:[[NSString stringWithFormat:@"Content-Disposition: form-data; name=\"parameter1\"\r\n\r\n"] dataUsingEncoding:NSUTF8StringEncoding]]; [body appendData:[[self postParametre] dataUsingEncoding:NSUTF8StringEncoding]]; [body appendData:[@"\r\n" dataUsingEncoding:NSUTF8StringEncoding]]; //Image upload [body appendData:[[NSString stringWithFormat:@"--%@\r\n", boundary] dataUsingEncoding:NSUTF8StringEncoding]]; [body appendData:[@"Content-Type: immage/jpg \r\n\r\n" dataUsingEncoding:NSUTF8StringEncoding]]; [body appendData:[@"Content-Disposition: form-data; filename=\"immagine.jpg\""dataUsingEncoding:NSUTF8StringEncoding]]; [body appendData:data]; [body appendData:[@"\r\n" dataUsingEncoding:NSUTF8StringEncoding]]; // Close boundary [body appendData:[[NSString stringWithFormat:@"\r\n--%@--\r\n", boundary] dataUsingEncoding:NSUTF8StringEncoding]]; // set request body [eventRequest setHTTPBody:body]; NSString* string = [[NSString alloc] initWithData:body encoding:NSUTF8StringEncoding]; NSLog(@"Stampa Dati inviati: %@", string); // Http header Content-Lenght [eventRequest setValue:[NSString stringWithFormat:@"%i",[data length]] forHTTPHeaderField:@"Content-Length"]; self.theConnection=[[NSURLConnection alloc] initWithRequest:eventRequest delegate:self]; if (self.theConnection) { self.receivedData = [[NSMutableData data] retain]; } else { // Inform the user that the connection failed. NSLog(@"Connection Problem"); } </code></pre> <p>can see that i set the i set the multipart/form-data for <code>"Content-Type"</code> in the first part of body i set che text and in the second i set the image, but the image was upload correctly but without the "extension" and in the first i set the text to send but the text apparently was not set or the format was not read to server.</p> <p>the method <code>[self postParametre]</code> return a <code>NSMutableString</code> with this format "key1=value1&amp;key2=value2&amp;key3=value3".</p> <p>anyone can help me?</p> <p>regards.</p>
    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.
 

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