Question:
I need to send a POST request to a server. That POST request have to be a multi-part message and the boundary have to be a specific boundary.
I've written the following code:
CkoHttp *http = [[CkoHttp alloc] init];
[http UnlockComponent:MYCODE];
//
CkoHttpRequest *ckRequest = [[CkoHttpRequest alloc] init];
[ckRequest setHttpVerb:@"POST"];
[ckRequest setPath:@"ServerApp/ServerApp.aspx?WCI=IWFiles"];
[ckRequest AddHeader:@"Connection" value:@"keep-alive"];
[ckRequest AddHeader:@"Accept" value:@"*/*"];
[ckRequest AddHeader:@"Accept-Encoding" value:@"gzip, deflate"];
[ckRequest setContentType:[NSString stringWithFormat:@"multipart/form-data; boundary=%@", boundary]];
//
NSString *boundary = @"B3DDA580-0F2D-44EE-B182-E131B56BEF97";
//
NSMutableData *postBody = [NSMutableData data];
[postBody appendData:[[NSString stringWithFormat:@"--%@\r\n", boundary] dataUsingEncoding:NSUTF8StringEncoding]];
//
[postBody appendData:[[NSString stringWithFormat:@"Content-Disposition: form-data; name=\"Filedata\"; filename=\"image.gif\"\r\n"] dataUsingEncoding:NSUTF8StringEncoding]];
[postBody appendData:[[NSString stringWithFormat:@"Content-Type: application/octet-stream\r\n\r\n"] dataUsingEncoding:NSUTF8StringEncoding]];
//
NSData *fdata = [[NSData alloc] initWithContentsOfFile:MYFILE];
[postBody appendData:fdata];
//
[postBody appendData:[[NSString stringWithFormat:@"\r\n--%@--", boundary] dataUsingEncoding:NSUTF8StringEncoding]];
//
[ckRequest LoadBodyFromBytes:postBody];
but it seems that what Chilkat does it to calculate automatically its own boundary. I expected this output:
POST http://MYSERVER/ServerApp/ServerApp.aspx?WCI=IWFiles HTTP/1.1
Host: MYSERVER
Connection: keep-alive
Accept-Encoding: gzip, deflate
Content-Type: multipart/form-data; boundary=B3DDA580-0F2D-44EE-B182-E131B56BEF97
Accept: */*
Content-Length: 408
Connection: keep-alive
--B3DDA580-0F2D-44EE-B182-E131B56BEF97
Content-Disposition: form-data; name="Filedata"; filename="image.gif"
Content-Type: application/octet-stream
GIF89a...
--B3DDA580-0F2D-44EE-B182-E131B56BEF97--
Instead I get this:
POST http://MYSERVER/ServerApp/ServerApp.aspx?WCI=IWFiles HTTP/1.1
Host: MYSERVER
Connection: keep-alive
Accept: */*
Accept-Encoding: gzip, deflate
Cookie: ASP.NET_SessionId=jwzsidvhqptkairkzsmlu5av
Content-Type: multipart/form-data; boundary=------------010303070609060703000504
Content-Length: 42
--------------010303070609060703000504--
with nothing in the body. I know that Chilkat automatically computes a boundary if it sees the word "multipart/form-data" into the content type property... but this does not work in my case. Is there a way of switching off this "automatic-multi-part" algorithm and let the programmer define content-type and body by himself?
Thanks!
I also have the same issue, is there a way to set a specific boundary?
Thanks
Nick