php卷曲后不工作
问题描述:
我的卷曲工作从命令行,但不是从PHP。它只是不发送PHP中的POST数据。 (我已经检查,看它是否改写为GET和它没有这样做,要么althought GET作品,如果我用GET)php卷曲后不工作
命令行:
curl -d "something=true" file.php
PHP:
error_reporting(E_ALL);
$ch = curl_init();
$post = 'something=true';
$arr = array();
array_push($arr, 'Accept: application/json, text/javascript, */*; q=0.01');
array_push($arr, 'Accept-Language: en-us,en;q=0.5');
array_push($arr, 'Accept-Encoding=gzip,deflate');
array_push($arr, 'Accept-Charset=ISO-8859-1,utf-8;q=0.7,*;q=0.7');
array_push($arr, 'Keep-Alive: 115');
array_push($arr, 'Connection: keep-alive');
array_push($arr, 'Content-Type: application/json; charset=utf-8');
array_push($arr, 'x-request-with: XMLHttpRequest');
array_push($arr, 'Content-Length: ' . strlen($post));
curl_setopt($ch, CURLOPT_HTTPHEADER, $arr);
curl_setopt($ch, CURLOPT_URL, 'http://mydomain.com/file.php');
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_USERAGENT, 'Mozilla/5.0 (Macintosh; U; Intel Mac OS X 10.6; en-US; rv:1.9.2.13) Gecko/20101203 Firefox/3.6.13');
curl_setopt($ch, CURLOPT_POSTFIELDS, $post);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, false);
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 0);
curl_exec($ch);
请参考: php curl post json
答
请勿设置Content-L自己动手,但让libcurl自己做,以减少犯错的风险。
然后,您添加了两个不含冒号的标头,而是使用'='代替,这可能会混淆接收端。
你有错误吗?它以什么方式不起作用? – Cfreak 2011-02-16 22:04:15