Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>Your data is wrong. If you expect the data to be found in the $_POST array of PHP, it should look like this:</p> <pre><code>const char *bytes = "mydata=Hello%20World"; </code></pre> <p>If you want to send XML Data, you need to set a different HTTP Content Type. E.g. you might set</p> <pre><code>application/xml; charset=utf-8 </code></pre> <p>If you set no HTTP Content Type, the default type</p> <pre><code>application/x-www-form-urlencoded </code></pre> <p>will be used. And this type expects the POST data to have the same format as it would have in a GET request.</p> <p>However, if you set a different HTTP Content Type, like application/xml, then this data is not added to the $_POST array in PHP. You will have to read the raw from the input stream.</p> <p>Try this:</p> <pre><code>NSString * str = [NSString stringWithFormat:@"&lt;?xml version=\"1.0\"?&gt;\n&lt;mydata&gt;%@&lt;/mydata&gt;", data]; [request setHTTPMethod:@"POST"]; [request setValue:@"application/xml; charset=utf-8" forHTTPHeaderField:@"Content-Type"]; [request setHTTPBody:[str dataUsingEncoding:NSUTF8StringEncoding]]; </code></pre> <p>and on the server try the following PHP:</p> <pre><code>$handle = fopen("php://input", "rb"); $http_raw_post_data = ''; while (!feof($handle)) { $http_raw_post_data .= fread($handle, 8192); } fclose($handle); </code></pre> <p>Please note that this only works if the HTTP header of your POST is not application/x-www-form-urlencoded. If it is application/x-www-form-urlencoded then PHP itself reads all the post data, decodes it (splitting it into key/value pairs), and finally adds it to the $_POST array.</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