2018-04-21 19:52
浏览 1.9k


I am now using GuzzleHttp to make HTTP requests, first I make a POST request to login.asp, which returns a response with Set-Cookie with a value that I need for future requests

enter image description here

When I inspect my obtained answer I get the following

enter image description here

As noted, I get all the keys except the Set-Cookie, what can be happening? How can I get this value? I'm using "guzzlehttp/guzzle": "^6.3", or can I get it using another tool?

    $jar = new CookieJar;

    $client = new Client([
        'base_uri' =>'miurl/',
        'timeout'  => 10.0,
        'cookies' => $jar

    $response = $client->request('POST', 'login.asp',  [
        'form_params' => [
            'pws' => '',//data password
            'user' => '',//data user

    //Request require coookies

    $response = $client->request('POST', 'goform/Wls',  [
        'form_params' => [
       //if I manually add a correct userid the post application works fine
        'headers' => [
            //Require cookie param userid 
            'Cookie' => 'LANG_COOKIE=lang_span; userid=1524324306',

Alternatively, I used this configuration without being able to obtain the cookie yet

checking a bit the answer using postman, is that after doing the correct login is still on the same page but with javascript redirect, can this influence?

<script language='JavaScript'>window.location='/admin/cable-Systeminfo.asp';</script>

The requests I make directly for a router hitron technologies cgnv22 to manage the mac filtering, I would like to provide more information but it is sensitive information

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

我现在正在使用GuzzleHttp发出HTTP请求,首先我向login.asp发出POST请求,返回一个 使用Set-Cookie响应我将来需要的值

当我 检查我获得的答案我得到以下

如上所述,我获得了所有密钥 除了Set-Cookie之外,会发生什么? 我怎样才能获得这个价值? 我正在使用“guzzlehttp / guzzle”:“^ 6.3”,或者我可以使用其他工具获取它吗?

  $ jar = new CookieJar  ; 
 $ client = new Client([
'base_uri'=&gt;'miurl /',
'timeout'=&gt; 10.0,
'cookies'=&gt; $ jar 
 $ response = $ client-&gt; request('POST','login.asp',[
'form_params'=&gt; [
'pws'=&gt;'',//数据密码\  n'用户'=&gt;'',//数据用户
 $ response = $ client-&gt; request('POST','  goform / Wls',[
'form_params'=&gt; [
 / * Form'Params * / 
'headers'=  &gt; [
 //要求cookie param userid 
'Cookie'=&gt;'LANG_COOKIE = lang_span; userid = 1524324306',
 \  n 

检查一下 使用postman回答,是在正确登录后仍然在同一页面上但是使用javascript重定向,这会影响吗?

 &lt; script language ='JavaScript'&gt;  window.location ='/ admin / cable-Systeminfo.asp';&lt; / script&gt; 
&lt; / html&gt; 

我直接为a做出的请求 路由器hitron技术cgnv22管理mac过滤,我想提供更多信息,但它是敏感信息

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

1条回答 默认 最新

  • doujiaoang69440 2018-05-16 00:39

    It seems you're making the request the right way, passing an instance of CookieJarInterface. However, you shouldn't expect the Set-Cookie header. Instead, inspect your jar to check what cookies were returned.

    The following example shows how you can iterate over all cookies:

    $client = new \GuzzleHttp\Client();
    $jar = new \GuzzleHttp\Cookie\CookieJar();
    $request = $client->request('GET', '', [
        'cookies' => $jar
    $it = $jar->getIterator();
    while ($it->valid()) {

    Here is a sample output from the snippet above:

    object(GuzzleHttp\Cookie\SetCookie)#36 (1) {
      array(9) {
        string(3) "NID"
        string(132) "130=dmyl6v*******"
        string(11) ""
        string(1) "/"

    Refer to the CookieJar class source for more information on how you can access the returned cookies. Additionally, you can take a look at the docs for ArrayIterator class.

    打赏 评论

相关推荐 更多相似问题