Loading a cookie and posting data with curl

自古美人都是妖i 提交于 2019-12-23 04:53:37

问题


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?


回答1:


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.



来源:https://stackoverflow.com/questions/6019294/loading-a-cookie-and-posting-data-with-curl

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!