Reputation: 81
I want to make an login with CURL on a site, looking like
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);
Upvotes: 2
Views: 4236
Reputation: 21513
curl doesn't send the Expect header unless the post data is over a certain size, your sample code does not send an Expect header either way. if you need some random data to make the Expect header be generated in your sample code, add 'data'=>str_repeat("\x00",1*1024)
, that will add 1 kilobyte of nulls which will make your sample code send the Expect header. that said, i can not reproduce the issue, this is the POST request sent without removing 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=------------------------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--
and if i remove the Expect header, here is the new request:
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--
as you can see, curl_setopt($ch, CURLOPT_HTTPHEADER, array('Expect: '));
did not change the request type from POST to GET, hence i'm voting to close this issue as can not reproduce
Upvotes: 0
Reputation: 1108
You can have get and post simultaneously
curl_setopt($ch, CURLOPT_URL, "http://www.example.com/login.php?return=");
that is get.
Upvotes: 0