Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/245.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 带有get参数的CURL Post请求,预期标头_Php_Post_Curl_Header_Expect - Fatal编程技术网

Php 带有get参数的CURL Post请求,预期标头

Php 带有get参数的CURL Post请求,预期标头,php,post,curl,header,expect,Php,Post,Curl,Header,Expect,我想用CURL登录一个站点,看起来像 参数将随Post一起发送 curl_setopt($ch,CURLOPT_POST,TRUE)$data=array(“params”=>“param” ); curl_setopt($ch,CURLOPT_POSTFIELDS,$data) CURL正在设置一个 期望值:100继续页眉 我会得到一个 417-预期失败 作为回应 所以它不起作用了。当我尝试删除Expect标头时 curl_setopt($ch,CURLOPT_HTTPHEADER,数组('

我想用CURL登录一个站点,看起来像

参数将随Post一起发送

curl_setopt($ch,CURLOPT_POST,TRUE)
$data=array(“params”=>“param” );
curl_setopt($ch,CURLOPT_POSTFIELDS,$data)

CURL正在设置一个

期望值:100继续页眉

我会得到一个

417-预期失败

作为回应

所以它不起作用了。当我尝试删除Expect标头时

curl_setopt($ch,CURLOPT_HTTPHEADER,数组('Expect:')

CURL正在发送GET请求,而不是POST请求。我做错了什么

    $ch = curl_init();

    curl_setopt($ch, CURLOPT_RETURNTRANSFER, TRUE);
    curl_setopt($ch, CURLOPT_USERAGENT, $this->useragent);

    curl_setopt($ch, CURLOPT_URL, "http://www.example.com/login.php?return=");

    curl_setopt($ch, CURLOPT_REFERER, "http://www.example.com/login.php");

    curl_setopt($ch, CURLOPT_FOLLOWLOCATION, TRUE);
    curl_setopt($ch, CURLOPT_POST, TRUE);

    #curl_setopt($ch, CURLOPT_HTTPHEADER, array('Expect: '));

    $data = array (
        "param1" => $username,
        "param2" => $password
     );
    curl_setopt($ch, CURLOPT_POSTFIELDS, $data);

    $response = curl_exec ($ch); 
    curl_close($this->ch);

您可以同时获取和发布

curl_setopt($ch, CURLOPT_URL, "http://www.example.com/login.php?return=");

这就是get。

curl不会发送Expect标头,除非post数据超过一定大小,否则示例代码不会以任何方式发送Expect标头。如果需要一些随机数据来在示例代码中生成Expect标头,请添加
'data'=>str\u repeat(“\x00”,1*1024)
,这将添加1KB的空值,使示例代码发送Expect标头。也就是说,我无法复制该问题,这是未删除Expect而发送的POST请求:

POST / HTTP/1.1
Host: 127.0.0.1:9999
User-Agent: wut
Accept: */*
Referer: http://www.example.com/login.php
Content-Length: 1369
Content-Type: multipart/form-data; boundary=------------------------35f10eb804cdb5c6
Expect: 100-continue

--------------------------35f10eb804cdb5c6
Content-Disposition: form-data; name="param1"

username
--------------------------35f10eb804cdb5c6
Content-Disposition: form-data; name="param2"

password
--------------------------35f10eb804cdb5c6
Content-Disposition: form-data; name="data"


--------------------------35f10eb804cdb5c6--
如果删除Expect标头,则新请求如下:

POST / HTTP/1.1
Host: 127.0.0.1:9999
User-Agent: wut
Accept: */*
Referer: http://www.example.com/login.php
Content-Length: 1369
Content-Type: multipart/form-data; boundary=------------------------0a1590cb9de6d248

--------------------------0a1590cb9de6d248
Content-Disposition: form-data; name="param1"

username
--------------------------0a1590cb9de6d248
Content-Disposition: form-data; name="param2"

password
--------------------------0a1590cb9de6d248
Content-Disposition: form-data; name="data"


--------------------------0a1590cb9de6d248--
如您所见,
curl_setopt($ch,CURLOPT_HTTPHEADER,array('Expect:')
没有将请求类型从POST更改为GET,因此我投票决定结束此问题,因为
无法复制


尽管如此,如果您真的认为删除该标题会改变您的请求类型,请随意访问discord/facebook,我希望用自己的眼睛观察这种行为。

我知道这很奇怪,但网站需要这样做,那么我该怎么办呢?您是否在post数据中尝试了“return=”?除非post数据超过一定的大小,否则curl不会发送Expect头,您的示例代码也不会以任何方式发送Expect头。如果需要一些随机数据来在示例代码中生成Expect标头,请添加
'data'=>str\u repeat(“\x00”,1*1024)
,这将添加1KB的空值,使示例代码发送Expect标头