Loading a cookie and posting data with curl
If I load in a cookie, I am able to get to the page that requires cookies, like this:
$cookie = ".ASPXAUTH=Secret";
curl_setopt($ch, CURLOPT_COOKIE, $cookie);
No problem here, I can run curl_exec
, and see the page that requires cookies.
If I also want to send some post data, I can do like this:
$data = array(
'index' => "Some data 开发者_如何学编程is here"
);
$cookie = ".ASPXAUTH=Secret";
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_POSTFIELDS, $data);
curl_setopt($ch, CURLOPT_COOKIE, $cookie);
I have set up a dump script on my local server, to see if it is working. If i send only the cookie, I can see it in the http headers, and if I send only the post data, I can see the post data.
When I send both, I see only the cookie.
Why?
I finally found a solution.
If I manually set the cookie, using a custom http_header, I am able to get the results wanted.
curl_setopt($ch, CURLOPT_HTTPHEADER, array("Cookie:.ASPXAUTH=secretData"));
Even tried on different servers - same results.
精彩评论