How can I do a simple curl call with post field in objective c?

Go To


to be more specific, this is what I need to do in objective c, what is the equivalent for this?

curl_setopt($ch, CURLOPT_URL,"");
curl_setopt($ch, CURLOPT_POSTFIELDS, "a message to the site");
curl_setopt($ch, CURLOPT_CUSTOMREQUEST,"GET" );
curl_setopt($ch, CURLOPT_HTTPHEADER, array('Accept: Application/json'));
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
$server_output = curl_exec ($ch);
curl_close ($ch);
2012-04-04 06:07
by Dima


What about using a NSURLRequest and NSURLConnection.

NSURLRequest: you can init it with an URL, set the POST variables as HTTP Body, be sure the set the head correctly (eg: google for an example).

Then load the NSURLRequest with an NSURLConnection, even asynchronous as synchronous as you want.

See Append data to a POST NSURLRequest and iPhone sending POST with NSURLConnection

2012-04-04 06:12
by Jelle De Laender
i tried this for over a week now, im still getting an empty string in the post on the server sid - Dima 2012-04-04 06:40