Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>While I wouldn't recommend it (I'd prefer to see a well-formed <code>multipart/form-data</code> or <code>application/JSON</code> request), you could create your request like so:</p> <pre><code>NSData *zipData = [NSData dataWithContentsOfFile:zipFile]; // note, autorelease object NSString *postLength = [NSString stringWithFormat:@"%d", [zipData length]]; NSMutableURLRequest *request = [NSMutableURLRequest requestWithURL:[NSURL URLWithString:urlString]]; [request setHTTPMethod:@"POST"]; [request setValue:postLength forHTTPHeaderField:@"Content-Length"]; [request setValue:@"application/zip" forHTTPHeaderField:@"Content-Type"]; [request setHTTPBody:zipData]; [NSURLConnection sendAsynchronousRequest:request queue:[NSOperationQueue mainQueue] completionHandler:^(NSURLResponse *response, NSData *data, NSError *connectionError) { NSString *result = [[[NSString alloc] initWithData:data encoding:NSUTF8StringEncoding] autorelease]; NSInteger statusCode = -1; if ([response isKindOfClass:[NSHTTPURLResponse class]]) statusCode = [(NSHTTPURLResponse *)response statusCode]; NSLog(@"Response Code: %d", statusCode); if (statusCode &gt;= 200 &amp;&amp; statusCode &lt; 300) { NSLog(@"Response: %@", result); } }]; </code></pre> <p>And then you could have PHP code that reads this binary data and saves it to a file:</p> <pre><code>&lt;?php $handle = fopen("php://input", "rb"); $http_raw_post_data = ''; while (!feof($handle)) { $http_raw_post_data .= fread($handle, 8192); } fclose($handle); $handle = fopen('upload/myzip.zip', 'wb'); if ($handle == false) { echo 'unable to open file'; exit (0); } $bytes = fwrite($handle, $http_raw_post_data); if ($bytes == false) echo 'write failed'; else echo 'write succeeded'; fclose($handle); ?&gt; </code></pre>
 

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