login about faq
1
1

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!

asked Mar 28 '14 at 06:24

lbaldini71's gravatar image

lbaldini71
21235

There is no way, i was also stuck with same. I instead of using chilkat used native http class of .net(i was using .net platform) to do just that part where it required boundry. Got cookie from getcookiexml method of chilkat. I wish they answer to this :)

(Jun 18 '14 at 08:41) aki003

I also have the same issue, is there a way to set a specific boundary?

Thanks

Nick

link

answered Jun 17 '14 at 09:44

nick's gravatar image

nick
161

Your answer
toggle preview

Follow this question

By Email:

Once you sign in you will be able to subscribe for any updates here

By RSS:

Answers

Answers and Comments

Markdown Basics

  • *italic* or __italic__
  • **bold** or __bold__
  • link:[text](http://url.com/ "title")
  • image?![alt text](/path/img.jpg "title")
  • numbered list: 1. Foo 2. Bar
  • to add a line break simply add two spaces to where you would like the new line to be.
  • basic HTML tags are also supported

Tags:

×6
×3

Asked: Mar 28 '14 at 06:24

Seen: 1,880 times

Last updated: Jun 18 '14 at 08:41

powered by OSQA