我尝试发送请求(发布请求)到网址但返回
HTTP/1.1 400 Bad Request
content-disposition: attachment; filename=json.json
content-length: 118
content-type: application/json;charset=utf-8
date: Sat, 02 Sep 2017 11:33:56 GMT
server: tsa_o
strict-transport-security: max-age=631138519
vary: Origin
x-connection-hash: 32931e6376249fb1689df3203e847a2b
x-content-type-options: nosniff
x-frame-options: SAMEORIGIN
x-response-time: 108
x-transaction: 0021b7c8005c6a4e
x-tsa-request-body-time: 1
x-xss-protection: 1; mode=block
{ “capsError”: “insufficientpermission”, “的requestId”:“4f0c87b1349996812fafe51ca6a8197b5bb1e9d560d7dcb8a450ab 3c890e40ac“}
我的代码
$ch = curl_init();
curl_setopt_array($ch, array(
CURLOPT_URL => $URL,
CURLOPT_POST => true,
CURLOPT_POSTFIELDS => 'postField',
CURLOPT_COOKIEJAR => realpath("cookies/" . $name . ".txt"),
CURLOPT_COOKIEFILE => realpath("cookies/" . $name . ".txt"),
CURLOPT_CONNECTTIMEOUT=>30,
CURLOPT_HEADER => true, // return headers
CURLOPT_SSL_VERIFYPEER=>true,
));
$output = curl_exec($ch);
curl_close( $ch );
return $output;
Iam肯定来自所有后场但相同的回应 但是在浏览器中,Every Thing就可以了
答案 0 :(得分:0)
首先,您可以将$output = curl_exec($ch);
更改为echo $output = curl_exec($ch);
。这样您就会在浏览器中看到错误消息。
另外,请尝试urlencode($ url);如果您的网址中有一些空格。
但是您的问题很可能是目标服务器的安全性。许多服务器将cURL视为跨站点伪造攻击。这就是为什么任何cURL脚本必须包含目标页面的csrf标记到它的post参数。
您必须首先从目标页面找到令牌,然后编写代码,以便您的脚本将解析curl_exec输出字符串中的令牌。
答案 1 :(得分:0)
您始终可以重写代码。
类似的东西:
$http_headers = array(
'Mozilla/5.0 (Windows NT 6.1) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/60.0.3112.101 Safari/537.36',);
$crl = curl_init();
$url = "http://www.example.gr/node/add/content";
curl_setopt($crl, CURLOPT_URL, $url);
curl_setopt($crl, CURLOPT_COOKIEFILE, "/tmp/cookie.txt");
curl_setopt ($crl, CURLOPT_COOKIEJAR, "/tmp/cookie.txt");
curl_setopt ($crl, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($crl, CURLOPT_HEADER, true);
curl_setopt($crl, CURLOPT_HTTPHEADER, $http_headers);
curl_setopt($crl, CURLOPT_SSL_VERIFYHOST, 0);
curl_setopt($crl, CURLOPT_SSL_VERIFYPEER, 0);
curl_setopt($crl, CURLOPT_FOLLOWLOCATION, 1);
curl_setopt($crl, CURLOPT_USERAGENT, "Mozilla/5.0 (Windows NT 6.1) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/60.0.3112.101 Safari/537.36");
curl_setopt ($crl, CURLOPT_POSTFIELDS, $postdata);
echo $result=curl_exec($crl);
curl_setopt($crl, CURLOPT_POST, 1);
$postdata = array(
"title_field[und][0][value]"=>"category",
"op"=>"Save", );
curl_setopt ($crl, CURLOPT_POSTFIELDS, $postdata);
echo $result=curl_exec($crl);
你的版本可能出现了许多问题。如果这不能重新检查我在第一篇文章中所写的内容。