Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/248.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
PHP CURL不作为POST发送_Php_Rest_Curl - Fatal编程技术网

PHP CURL不作为POST发送

PHP CURL不作为POST发送,php,rest,curl,Php,Rest,Curl,我有以下简单的代码: $ch = curl_init($url); curl_setopt($ch, CURLOPT_HEADER, false); curl_setopt($ch, CURLOPT_POST, true); curl_setopt($ch, CURLOPT_POSTFIELDS, array('name' => 'michael')); curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); $data = curl_exec($ch);

我有以下简单的代码:

$ch = curl_init($url);
curl_setopt($ch, CURLOPT_HEADER, false);
curl_setopt($ch, CURLOPT_POST, true);
curl_setopt($ch, CURLOPT_POSTFIELDS, array('name' => 'michael'));
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
$data = curl_exec($ch);
curl_close($ch);

当我在另一台Windows7XAMPP计算机上尝试此功能时,它以POST的形式发送,效果很好。但后来我去了另一台Windows7XAMPP计算机,它以GET的形式发送它。API和post上的代码完全相同。我在API上检查了这个方法,它说它以GET的形式出现,但在另一台计算机上没有问题。两者都运行Windows7和xamp。不知道发生了什么事。我也尝试过使用任何POSTFIELDS和普通字符串,但没有帮助。谢谢

你能在看wireshark的时候运行它并告诉我们它使用的是什么方法吗?我从来没有使用过这个程序,尝试过,但是迷路了。但是
$\u服务器['REQUEST\u METHOD']
在API端显示GET(它是我的API)。但是在另一台机器上,我的xampp安装可能有问题吗?是的,可能版本不同吗?是否安装了不同版本的curl?奇怪的尝试使用带有值的“POST”,看看会发生什么?不起作用的一个是新安装的xampp,另一个是几个月前安装的。这也没用。谢天谢地,我发现CURLOPT_VERBOSE比wireshark更容易用于调试curl问题。显示请求和响应头等。