CURL Post request with get parameter, Expect header

I want to make an login with CURL on a site, looking like

http://www.example.com/login.php?return=

The parameters are going to send with Post

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

CURL is setting an

Expect: 100-continue Header

and I will get an

417 - Expectation Failed

as response.

So it isn't working. When i try to remove the Expect Header

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

CURL is sending a GET request and not a POST request. What am I doing wrong?

    $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);

You cna have simutaneously get and post

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

that is get.

Sorry this should be a comment - I dont have 50 reputation

链接地址: http://www.djcxy.com/p/48886.html

上一篇: C ++

下一篇: CURL Post请求,带有get参数,Expect标题