1

I made a small prototype for my program in Python, in which I need to log in to a website. For doing that I did:

import requests as req

session = req.Session()
req.post("somesite.com", data={"procedure": "login", "username": "JohnSmith", "password": "hunter7"})

And all of my API calls later worked well.

However, in Rust (using ureq), I can't seem to accomplish that. This is my code:

let agent = ureq::Agent::new();
agent.post("somesite.com")
      .query("procedure", "login")
      .query("username", "JohnSmith")
      .query("password", "hunter7")
      .call().unwrap();

I have checked and in the Rust version there isn't any session cookie, unlike in the Python version.

kmdreko
  • 42,554
  • 6
  • 57
  • 106
Ekain06
  • 21
  • 3
  • I forgot to specify in the post, I *did* enable the "cookies" feature of ureq in my Cargo.toml. – Ekain06 Oct 25 '21 at 15:26
  • 1
    The `query()` method seems to be for URL query parameters, meanwhile in Python version you are presumably sending the payload via POST body. Have you tried [send_form](https://docs.rs/ureq/2.3.0/ureq/struct.Request.html#method.send_form)? – justinas Oct 25 '21 at 15:30
  • @justinas Thank you very much! I didn't even see that method on docs.rs, and I thought I had to do it with URL parameters since Firefox's DevTools showed the request using a ?key=val&otherkey=val format. – Ekain06 Oct 25 '21 at 15:43

1 Answers1

1

As @justinas said, I needed to use Request::send_form instead of query.

kmdreko
  • 42,554
  • 6
  • 57
  • 106
Ekain06
  • 21
  • 3