简体   繁体   English

如何在get请求中发送下一个cookie?

[英]How to send the next cookies in get request?

I receive 503 error, but if i send it from inspect element its fine. 我收到503错误,但是如果我从inspect元素发送它,那很好。

The code worked for me before, but in the last few hours the specific website added cf_clearance and I need to add it to the request as well 该代码之前对我有用,但是在过去的几个小时中,特定网站添加了cf_clearance,我也需要将其添加到请求中

How do i send the both cookies? 如何发送两个Cookie?

$opts = array(
'http'=>array(
'method'=>"GET",
'proxy'=>"",
'header'=> "User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:51.0) Gecko/20100101 Firefox/51.0\r\n" .
           "Cookie: cf_clearance=3de18fcd39d55ce82d9db-1529352303-31536000; PHPSESSID=oahfun4m7vi3edd71\r\n"
));
$context = stream_context_create($opts);
$url = "http://website.com";

$data = file_get_contents($url, false, $context);

echo $data;

There's a pretty good example in the documentation . 文档中有一个很好的例子。

$opts = array(
  'http'=>array(
    'method'=>"GET",
    'header'=>"Accept-language: en\r\n" .
              "Cookie: foo=bar\r\n"
  )
);

Add line breaks and concatenate. 添加换行符并连接。 Your example right now should be resulting in a syntax error because you are not concatenating the two strings. 现在的示例应该导致语法错误,因为您没有将两个字符串连接在一起

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM