0

I'm using reqwest to send Post requests to an api behind Cloudflare. The problem is that Cloudflare blocks my requests if it's not in a standard format, even if it deviates slightly from the expected request format (for example, the order of headers matter!).

I tried proxying my requests to BurpSuite to check the full plain text of them and everything was good and Cloudflare didn't block me (Note: BurpSuite is not VPN. It's a local proxy app that lets you view/edit your network traffic!). But without proxy, I only get back a Cloudflare block page. I'm guessing when request goes through proxy, the order of headers changes to the correct format!

Now my question is, How do I print the whole request as text before sending it, without a proxy? And how do I make sure this doesn't happen later?

// this works:
// let proxy = reqwest::Proxy::https("127.0.0.1:8080")?;
// let client = reqwest::Client::builder().proxy(proxy).build()?;

// this doesn't work!
let client = reqwest::Client::builder().build()?;

let mut headers = reqwest::header::HeaderMap::new();

headers.insert("User-Agent", "some text".parse().unwrap());
headers.insert(reqwest::header::ACCEPT, "application/json".parse().unwrap());

let data = "{\"message\": \"Hello\", \"options\": {}}";

let request = client
    .post("https://myAPI.com/api/v1/")
    .headers(headers)
    .body(data);

let response = request.send().await?.text().await?;

println!("{}", response);
Gudarzi
  • 486
  • 3
  • 7
  • 22

0 Answers0