开发者

Loading a cookie and posting data with curl

开发者 https://www.devze.com 2023-03-06 01:17 出处:网络
If I load in a cookie, I am able to get to the page that requires cookies, like this: $cookie = \".ASPXAUTH=Secret\";

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.

0

精彩评论

暂无评论...
验证码 换一张
取 消