Giter Site home page Giter Site logo

Missing cookie in response about reqwest HOT 4 CLOSED

MannyFik avatar MannyFik commented on June 7, 2024
Missing cookie in response

from reqwest.

Comments (4)

pfernie avatar pfernie commented on June 7, 2024 1

Looking in Postman, there are indeed redirects on this request:
image
Only the first response in the chain has Set-Cookie for PHPSESSID-FRONT, so when you examine the (final) response you don't see it. If you inspect the contents of jar in your original example, instead of response.cookies(), you will find the PHPSESSID-FRONT cookie is stored, as is the case w/ the reqwest_cookie_store version.

_response_ cookie names:
["AWSALBTG", "AWSALBTGCORS"]
_jar_ cookie names:
"applicationId"
" AWSALBTG"
" AWSALBTGCORS"
" PHPSESSID-FRONT"

from reqwest.

MannyFik avatar MannyFik commented on June 7, 2024

I resolved my issue using a cookie store:

[dependencies]
tokio = { version = "1", features = ["full"] }
reqwest = "0.12.2"
reqwest_cookie_store= "0.7.0"
use tokio;
use std::sync::Arc;
use reqwest::{self, Client, Url};
use reqwest_cookie_store::{RawCookie, CookieStore};


#[tokio::main]
async fn main() {
    let application_id = "21891030";
    let cookie = RawCookie::new("applicationId", application_id);
    let mut cookie_store = CookieStore::new(None);
    let domain_url = format!("https://sport.nubapp.com").parse::<Url>().unwrap();
    let _ = cookie_store.insert_raw(&cookie, &domain_url);
    let cookie_store = reqwest_cookie_store::CookieStoreMutex::new(cookie_store);
    let cookie_store = Arc::new(cookie_store);
    let client = Client::builder()
        .cookie_provider(Arc::clone(&cookie_store))
        .build()
        .unwrap();
    let url = format!("https://sport.nubapp.com/web/cookieChecker.php?id_application={application_id}&isIframe=true");
    let response = client.get(url)
        .send()
        .await
        .unwrap();
    let cookies = response.cookies().collect::<Vec<reqwest::cookie::Cookie>>();
    let cookies_name = cookies.iter().map(reqwest::cookie::Cookie::name).collect::<Vec<&str>>();
    println!("{:?}", cookies_name);
    {
        // Examine the contents of the store.
        println!("Examining cookie store");
        let store = cookie_store.lock().unwrap();
        for c in store.iter_any() {
          println!("{:?}", c.name());
        }
    }
}

First print still returns ["AWSALBTG", "AWSALBTGCORS"]
Prints in the loop show

Examining cookie store
"AWSALBTG"
"PHPSESSID-FRONT"
"AWSALBTGCORS"
"applicationId"

I am still curious to understand why the PHPSESSID-FRONT cookie is not set in the response.

from reqwest.

seanmonstar avatar seanmonstar commented on June 7, 2024

Could it be that "missing" cookie comes from a redirect? Or has a different path/domain than the response?

from reqwest.

MannyFik avatar MannyFik commented on June 7, 2024

No same path and domain, and no redirect it seems.

from reqwest.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.