问题描述
如果我加载Cookie,我可以访问需要Cookie的网页,例如:
$ cookie =.ASPXAUTH = Secret;
curl_setopt($ ch,CURLOPT_COOKIE,$ cookie);
这里没有问题,我可以运行 curl_exec
,并查看需要Cookie的页面。
如果我还想发送一些帖子数据,我可以这样做:
code> $ data = array(
'index'=>有些数据在这里
);
$ cookie =.ASPXAUTH = Secret;
curl_setopt($ ch,CURLOPT_POST,1);
curl_setopt($ ch,CURLOPT_POSTFIELDS,$ data);
curl_setopt($ ch,CURLOPT_COOKIE,$ cookie);
我设置了在我的本地服务器,看看它是否工作。如果我只发送仅 Cookie,我可以在http标头中看到它,如果我发送仅发布数据,我可以看到发布数据。
当我发送两个时,我只看到cookie。
为什么?
p>
如果我手动设置cookie,使用自定义http_header,我可以得到想要的结果。
curl_setopt($ ch,CURLOPT_HTTPHEADER,array(Cookie:.ASPXAUTH = secretData));
即使尝试在不同的服务器上 - 结果相同。
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.
这篇关于加载Cookie并使用curl发布数据的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!