PHP-curl后视图请求正文(参数)

时间:2018-07-12 17:21:45

标签: php apache curl php-curl

发布cURL POST方法时,我收到关于缺少参数的错误响应, 我通过以下方式向CURLOPT_POSTFIELDS添加参数数组:

$service = "AutoInsuranceFormPostService";
$method = "autoInsurancePublisherFormPost";
$userAgent = "Mozilla%2F5.0+%28Linux%3B+Android+4.4.4%3B+Z752C+Build%2FKTU84P%29+AppleWebKit%2F537.36+%28KHTML%2C+like+Gecko%29+Chrome%2F36.0.1985.135+Mobile+Safari%2F537.36";
$payload = $encodedPayLoad;

$parameters = array (
    'service' => $service,
    'method' => $method,
    'UserAgent' => $userAgent,
    'payload' => $payload
);

使用:

curl_setopt($ch,CURLOPT_POSTFIELDS,$parameters);

由于响应中说缺少参数“ service”,因此我认为需要调试请求正文。 我设法获得标题:

curl_getinfo($ch)

我还尝试使用:

curl_setopt($ch, CURLOPT_VERBOSE, true);

但是不幸的是,在两种情况下,我都只有标头,而没有正文(参数值)。

完全卷曲执行功能:

function openurl($url, $postvars) {

$ch=curl_init();
curl_setopt($ch, CURLOPT_VERBOSE, true);
$verbose = fopen('php://temp', 'w+');
curl_setopt($ch, CURLOPT_STDERR, $verbose);
curl_setopt($ch,CURLOPT_URL,$url);
curl_setopt($ch, CURLOPT_POST, TRUE);
curl_setopt($ch,CURLOPT_POSTFIELDS,$postvars);
curl_setopt($ch, CURLOPT_HTTPHEADER, array('Content-Type: application/x-www-form-urlencoded'));
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch,CURLOPT_TIMEOUT, '3');

$result = curl_exec($ch);

rewind($verbose);
$verboseLog = stream_get_contents($verbose);
echo "Verbose information:\n<pre>", htmlspecialchars($verboseLog), "</pre>\n";
return $result;
}

言语信息:

Content-Length: 6659
Expect: 100-continue
Content-Type: application/x-www-form-urlencoded; boundary=------------------------45b2d9f6776306b0

< HTTP/1.1 100 Continue
< HTTP/1.1 200 OK
< Date: Thu, 12 Jul 2018 16:32:52 GMT
< Server: Apache
< Cache-Control: public
< ORIGIN: S_CACHE
< Vary: User-Agent,Accept-Encoding
< Set-Cookie: _qs_origin=s-cache; path=/;
< Set-Cookie: _qs_deviceType=; path=/;
< Content-Length: 141
< Content-Type: application/json;charset=ISO-8859-1
< 

此输出对我来说是无用的,因为我看不到参数的发送方式以及那些参数无法修复其格式。

我得到的答复是:

{"Status":"Fail","StatusCode":"400","ResponseMessage":"\"service\" parameter empty! || \"method\" parameter empty! ","SkipMatchingFlag":"No"}

我整天都在寻找解决方案,在“如何看待响应正文”和“如何看待请求头”方面,我已经看到了很多答案。
但是“如何看待请求正文”一无所获,因此我们将不胜感激,
最好的祝福。

0 个答案:

没有答案
相关问题