I'm using Curl to upload photos to an actual site. I can see from Fiddler that the headers look like this:
Host: test.example.com
Proxy-Connection: keep-alive
Data-Type: json
Accept-Encoding: gzip, deflate
Content-Length: 62601
Content-Type: application/json
Accept-Language: en-us
Accept: application/json
Connection: keep-alive
User-Agent: Mozilla/5.0 (Windows NT 6.3; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/37.0.2049.0 Safari/537.36
I'm using the exact headers as above. I'm getting the value for content-length
using filesize
$file = 'test.jpg';
$file_size = filesize($file);
$headers = array(
"Host: test.example.com",
"Proxy-Connection: keep-alive",
"Data-Type: json",
"Accept-Encoding: gzip, deflate",
"Content-length: $file_size",
"Content-Type: application/json",
"Accept-Language: en-us",
"Connection: keep-alive",
"Mozilla/5.0 (Windows NT 6.3; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/37.0.2049.0 Safari/537.36",
);
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_POSTFIELDS, $data);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);
$result = curl_exec($ch);
I don't actually need the headers, the script generally works without it, but it fails too frequently and in an effort to troubleshoot I put the headers in.
All the headers work fine except for content-length
. When I put that in I get a response from the server that indicates the command is not well formed (I cannot show the actual response here). I do not understand a lot about content-length
but I believe this tells the server the size of the file and it helps it determine that the upload is complete. I think if I had this properly working it would increase the stability of my script.
I would appreciate any help.