login about faq

I'm using CkoHTTP to send a POST request to a server. The problem is that I have to send a QueryString, a Body with a POST request. Is that possible? I'm using the following code but it seems that if there is a BODY only the BODY gets sent... if there is no BODY the QueryString "moves" into the body.

CkoHttp *http = [[CkoHttp alloc] init];
CkoHttpRequest *ckRequest = [[CkoHttpRequest alloc] init];
[ckRequest setHttpVerb:@"POST"];
[ckRequest SetFromUrl:@"http://www.someurl.com?CMD=READDATA"];
[ckRequest AddHeader:@"Connection" value:@"keep-alive"];
[ckRequest AddHeader:@"Accept" value:@"*/*"];
[ckRequest AddHeader:@"Accept-Encoding" value:@"gzip, deflate"];
[ckRequest AddHeader:@"User-Agent" value:_USER_AGENT];
[ckRequest AddHeader:@"PAR1" value:@"Value1"];
[ckRequest AddHeader:@"PAR2" value:@"Value2"];
[ckRequest LoadBodyFromBytes:HTTPBody];
//
[http setFetchFromCache:NO];
[http setConnectTimeout:[NSNumber numberWithInt:60]];      // 60 seconds
[http setReadTimeout:[NSNumber numberWithInt:15*60]];      // 15 minutes
//
CkoHttpResponse *ckResponse = [http SynchronousRequest:@"www.someurl.com" port:[NSNumber numberWithInt:80] ssl:NO req:ckRequest];

Is there a way of sending BODY parameters AND the QueryString part if the method is a POST?

Thanks.

asked Mar 21 '14 at 12:09

lbaldini71's gravatar image

lbaldini71
21235

edited Mar 21 '14 at 12:12


I'm sorry, I was mistaken. I think the solution is to use SynchronousRequest, but to not use HttpRequest.SetFromUrl. Instead, set the HttpRequest.Path explicitly to "/?CMD=READDATA".

link

answered Mar 25 '14 at 07:31

chilkat's gravatar image

chilkat ♦♦
11.8k316358420

Try using the PostUrlEncoded method instead, which allows you to specify the URL directly in the method arguments.

link

answered Mar 24 '14 at 13:17

chilkat's gravatar image

chilkat ♦♦
11.8k316358420

Unfortunately it does not work... The PostUrlEncoded sends only the parameters in the body (as expected) but it does not send the QueryString part (that I need).

link

answered Mar 25 '14 at 04:52

lbaldini71's gravatar image

lbaldini71
21235

Perfect! Now it works and it sends the QueryString even with post... I had to write this:

if (MyURL.query && MyURL.query.length > 0)
  [ckRequest setPath:[NSString stringWithFormat:@"%@?%@", MyURL.path, MyURL.query]];
else
  [ckRequest setPath:MyURL.path];

and now it works. Thanks!

link

answered Mar 25 '14 at 11:40

lbaldini71's gravatar image

lbaldini71
21235

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:

×186
×26
×8
×1

Asked: Mar 21 '14 at 12:09

Seen: 2,197 times

Last updated: Mar 25 '14 at 11:40

powered by OSQA