2012-05-17 10:21
浏览 286


This is my code:

$ch = curl_init('');
curl_setopt($ch,CURLOPT_COOKIE,"shippingCountry=US; currency=USD");
curl_setopt ($ch, CURLOPT_COOKIEFILE, "C:/cookie-techenclave.txt");
curl_setopt($ch, CURLOPT_COOKIEJAR, "C:/cookie-techenclave.txt");
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, TRUE);     // Follow redirects
curl_setopt($ch, CURLOPT_MAXREDIRS, 8);             // Limit redirections to four
curl_setopt($ch, CURLOPT_RETURNTRANSFER, TRUE);     // Return in string

$pageString = curl_exec($ch);
curl_close($ch) ;

The 2 cookies I am attempting to set are not getting set. I tested this with netcat. This is the output captured by netcat.

D:\php\L.c.MSQL.E.T.DVD\EF\SQL> "D:\My Downloads\apps
c.exe" -l -p 80
GET /beauty/index_template.php HTTP/1.1
User-Agent: Opera/9.80 (Windows NT 5.1; U; en) Presto/2.10.229 Version/11.64
Host: localhost
Accept: text/html, application/xml;q=0.9, application/xhtml+xml, image/png, image/webp, image/jpeg, image/gif, image/x-x
bitmap, */*;q=0.1
Accept-Language: en-US,en;q=0.9
Accept-Encoding: gzip, deflate
Connection: Keep-Alive

As can be seen there is no cookie header in there. What am I doing wrong? What else can i try? I tried capturing and setting all the headers , but again the cookies I am attempting to set didn't have any effect.


图片转代码服务由CSDN问答提供 功能建议


  $ ch = curl_init(  '');
curl_setopt($ch,CURLOPT_COOKIE,"shippingCountry=US; currency = USD“); 
curl_setopt($ ch,CURLOPT_COOKIEFILE,”C:/ cookie-  techenclave.txt“); 
curl_setopt($ ch,CURLOPT_COOKIEJAR,”C:/cookie-techenclave.txt“); 
curl_setopt($ ch,CURLOPT_FOLLOWLOCATION,TRUE);  //关注redirects 
curl_setopt($ ch,CURLOPT_MAXREDIRS,8);  //将重定向限制为四个
curl_setopt($ ch,CURLOPT_RETURNTRANSFER,TRUE);  //以字符串形式返回
 $ pageString = curl_exec($ ch); 
curl_close($ ch); 

我试图设置的2个cookie 没有设定。 我用netcat测试了它。 这是netcat捕获的输出。

  D:\ php \ L.c.MSQL.E.T.DVD \ EF \ SQL>  “D:\ My Downloads \ apps 
c.exe”-l -p 80 
GET /beauty/index_template.php HTTP / 1.1 
User-Agent:Opera / 9.80(Windows NT 5.1; U; en)Presto /  2.10.229版本/ 11.64 
接受:text / html,application / xml; q = 0.9,application / xhtml + xml,image / png,image / webp,image / jpeg,image / gif,image / xx  
bitmap,* / *; q = 0.1 
Accept-Language:en-US,en; q = 0.9 

可以看出,那里没有cookie标题。 我究竟做错了什么? 我还能尝试什么? 我尝试捕获并设置所有标题,但我尝试设置的cookie再没有任何效果。


  • 写回答
  • 关注问题
  • 收藏
  • 邀请回答

1条回答 默认 最新

  • duanjieyi6582 2012-05-17 10:48

    Don't use CURLOPT_COOKIE if you want curl auto update cookie's value base on server response. because request cookie will hardcoded to the value of CURLOPT_COOKIE. CURLOPT_COOKIEFILE and CURLOPT_COOKIEJAR will be ignored on this case.

    And are you sure the provided network sniff is from the above PHP code? I don't see the USER_AGENT get set on the code but it's available on your sniff.

    打赏 评论

相关推荐 更多相似问题