Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/linux/23.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(linux)中使用POST方法通过curl时,URL在符号和后被截断_Php_Linux_Curl_Https - Fatal编程技术网

在PHP(linux)中使用POST方法通过curl时,URL在符号和后被截断

在PHP(linux)中使用POST方法通过curl时,URL在符号和后被截断,php,linux,curl,https,Php,Linux,Curl,Https,PHP代码: $fields_string = ""; foreach ($postingfields as $key=>$value) { $fields_string .= $key . '=' . urlencode($value) . '&'; } $fields_string = rtrim($fields_string,'&'); $ch = curl_init(); curl_setopt($ch,CURLOPT_URL,$client_url)

PHP代码:

$fields_string = "";
foreach ($postingfields as $key=>$value) {
    $fields_string .= $key . '=' . urlencode($value) . '&';
}

$fields_string = rtrim($fields_string,'&');

$ch = curl_init();

curl_setopt($ch,CURLOPT_URL,$client_url);
curl_setopt($ch,CURLOPT_POST,true);
curl_setopt($ch,CURLOPT_POSTFIELDS,$fields_string);
curl_setopt($ch,CURLOPT_RETURNTRANSFER, true);

$result = curl_exec($ch);
$response = curl_getinfo( $ch );

curl_close($ch);
$client\u url
php变量保存值:
https://pcloudtest.com/Default.aspx?cid=99938
$fields\u string
php变量包含以下值:
&sid=30&title=Mr&firstname=Charles&name=Smith

目标服务器已设置为使用以下HTML进行响应:

当我调试(在linux中将信息发送到单独的txt文件)时,$result的值为:

<URL>https://pcloudtest.com/Default.aspx?cid=99938</URL>
我已经尽我所能弄清楚为什么php curl函数显然发送了一个缩短的URL,即直到第一次出现一个符号为止。我上面的代码逻辑已经几个月没有改变了,并且正在为其他目标服务器工作。 我可能会补充说,此逻辑没有问题的其他目标服务器是http:sites而不是https:。但另一端的技术人员向我保证,这肯定与发布到https网站无关


请帮忙。我希望我已经足够清楚地概述了我的问题,如果没有,请告知我可以提供的更多信息。

我认为您对
GET
POST
感到困惑,foreach循环毫无意义。curl将愉快地接受一个key:value对数组,并在适当的查询字符串中完成所有转换数组的工作。在发布帖子时,查询参数进入请求主体,而不是URL。实际上我一点也不困惑。我知道其中的区别,编写这段代码的目的是使用POST而不是GET执行curl。至于foreach循环,不管它是否无用,它在过去一直有效,现在仍然有效。我不是在问我提供的代码是否是最有效的。我希望您能提出一些建设性的意见,而不是那些不能带来可能的解决方案的意见。
https://pcloudtest.com/Default.aspx?cid=99938&sid=30&title=Mr&firstname=Charles&surname=Smith