Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>Try to change</p> <pre><code>string postData = "--" + boundary + "\nContent-Disposition: form-data\n"; </code></pre> <p>to</p> <pre><code>string postData = "\n\n--" + boundary + "\nContent-Disposition: form-data\n\n"; </code></pre> <p>And better also replace all \n to \r\n. At least first two newlines worked for me solving "Header section has more than 10240 bytes (maybe it is not properly terminated)" problem.</p> <p>And this code doesn't look correct:</p> <pre><code>postData += "myId=123&amp;someFk=456"; </code></pre> <p>My objective-C code for iPhone app which I am using and which works now looks like this:</p> <pre><code>NSMutableData *reqData = [NSMutableData data]; NSURL *encUrl; encUrl = [NSURL URLWithString:[NSString url]; NSMutableURLRequest *request = [NSMutableURLRequest requestWithURL:encUrl]; request.HTTPMethod = @"POST"; request.timeoutInterval = kServerConnectionTimeout; NSString *stringBoundary = [NSString stringWithString:@"Multipart-Boundary"]; // TODO - randomize this NSString *contentType = [NSString stringWithFormat:@"multipart/form-data; boundary=\"%@\"",stringBoundary]; [request addValue:contentType forHTTPHeaderField: @"Content-Type"]; [reqData appendData:[[NSString stringWithFormat:@"\r\n\r\n--%@\r\n",stringBoundary] dataUsingEncoding:NSUTF8StringEncoding]]; for (id key in [self.parameters allKeys]) { if (![key isEqualToString:@"image"]) { NSString *val = [self.parameters objectForKey:key]; if (val != nil) { [reqData appendData:[[NSString stringWithFormat:@"Content-Disposition: form-data; name=\"%@\"\r\n",key] dataUsingEncoding:NSUTF8StringEncoding]]; [reqData appendData:[[NSString stringWithFormat:@"Content-Type: text/plain\r\n"] dataUsingEncoding:NSUTF8StringEncoding]]; [reqData appendData:[[NSString stringWithFormat:@"Content-Transfer-Encoding: 8bit\r\n\r\n"] dataUsingEncoding:NSUTF8StringEncoding]]; [reqData appendData:[[NSString stringWithFormat:@"%@",val] dataUsingEncoding:NSUTF8StringEncoding]]; [reqData appendData:[[NSString stringWithFormat:@"\r\n--%@\r\n",stringBoundary] dataUsingEncoding:NSUTF8StringEncoding]]; } } } // send binary part last if ([self.parameters objectForKey:@"image"]) { NSString *key = @"image"; NSData *imageData = [self.parameters objectForKey:key]; if (imageData != nil) { [reqData appendData:[[NSString stringWithFormat:@"Content-Disposition: form-data; name=\"image\";filename=\"avatar.png\"\r\n"] dataUsingEncoding:NSUTF8StringEncoding]]; [reqData appendData:[[NSString stringWithFormat:@"Content-Type: image/png\r\n"] dataUsingEncoding:NSUTF8StringEncoding]]; [reqData appendData:[[NSString stringWithFormat:@"Content-Transfer-Encoding: binary\r\n\r\n"] dataUsingEncoding:NSUTF8StringEncoding]]; [reqData appendData:imageData]; [reqData appendData:[[NSString stringWithFormat:@"\r\n--%@--\r\n",stringBoundary] dataUsingEncoding:NSUTF8StringEncoding]]; } } NSString * dataLength = [NSString stringWithFormat:@"%d", [reqData length]]; [request addValue:dataLength forHTTPHeaderField:@"Content-Length"]; request.HTTPBody = reqData; NSLog(@"postBody=%@", [[NSString alloc] initWithData:reqData encoding:NSASCIIStringEncoding]); </code></pre> <p>Hope this helps somebody.</p>
 

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