Skip to content

Commit 745fa25

Browse files
committed
Try to bypass cloudflare
1 parent 1d2b297 commit 745fa25

File tree

1 file changed

+41
-4
lines changed

1 file changed

+41
-4
lines changed

src/fetcher.rs

+41-4
Original file line numberDiff line numberDiff line change
@@ -97,10 +97,47 @@ pub async fn get_problem_async(problem_stat: StatWithStatus) -> Option<Problem>
9797
}
9898

9999
pub fn get_problems() -> Option<Problems> {
100-
reqwest::blocking::get(PROBLEMS_URL)
101-
.unwrap()
102-
.json()
103-
.unwrap()
100+
let headers = {
101+
let mut h = reqwest::header::HeaderMap::new();
102+
h.insert(
103+
"User-Agent",
104+
reqwest::header::HeaderValue::from_static(
105+
"Mozilla/5.0 (X11; Linux x86_64; rv:123.0) Gecko/20100101 Firefox/123.0",
106+
),
107+
);
108+
h.insert(
109+
"Referer",
110+
reqwest::header::HeaderValue::from_static(PROBLEMS_URL),
111+
);
112+
h.insert(
113+
"Origin",
114+
reqwest::header::HeaderValue::from_static(PROBLEMS_URL),
115+
);
116+
h.insert(
117+
"Content-Type",
118+
reqwest::header::HeaderValue::from_static("application/json"),
119+
);
120+
h.insert(
121+
"Accept",
122+
reqwest::header::HeaderValue::from_static("application/json"),
123+
);
124+
h.insert(
125+
"Host",
126+
reqwest::header::HeaderValue::from_static(PROBLEMS_URL),
127+
);
128+
h.insert(
129+
"X-Requested-With",
130+
reqwest::header::HeaderValue::from_static("XMLHttpRequest"),
131+
);
132+
h
133+
};
134+
let client = reqwest::blocking::Client::builder()
135+
.default_headers(headers)
136+
.build()
137+
.unwrap();
138+
let res = client.get(PROBLEMS_URL).send().unwrap().json();
139+
println!("{:?}", res);
140+
res.unwrap()
104141
}
105142

106143
#[derive(Serialize, Deserialize)]

0 commit comments

Comments
 (0)