wangluozhe / requests

用于快速请求HTTP或HTTPS,并支持修改ja3、ja4指纹
GNU General Public License v3.0
430 stars 100 forks source link

400 Bad Request #33

Closed gospider007 closed 1 year ago

gospider007 commented 1 year ago
package main

import (
    "fmt"

    "github.com/wangluozhe/requests"
    "github.com/wangluozhe/requests/url"
)

func main() {
    req := url.NewRequest()
    headers := url.NewHeaders()
    headers.Set("User-Agent", "Mozilla/5.0 (Windows NT 10.0; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/86.0.4240.198 Safari/537.36")
    req.Headers = headers
    req.Ja3 = "771,4865-4866-4867-49195-49199-49196-49200-52393-52392-49171-49172-156-157-47-53,0-23-65281-10-11-35-16-5-13-18-51-45-43-27-21,29-23-24,0"
    r, err := requests.Request("get", "https://www.thelancet.com/", req)
    if err != nil {
        fmt.Println(err)
    } else {
        fmt.Println("text:", r.Text)
        fmt.Println("StatusCode:", r.StatusCode)
    }
}
text: <html>
<head><title>400 Bad Request</title></head>
<body>
<center><h1>400 Bad Request</h1></center>
<hr><center>cloudflare</center>
</body>
</html>
<!-- a padding to disable MSIE and Chrome friendly error page -->
<!-- a padding to disable MSIE and Chrome friendly error page -->
<!-- a padding to disable MSIE and Chrome friendly error page -->
<!-- a padding to disable MSIE and Chrome friendly error page -->
<!-- a padding to disable MSIE and Chrome friendly error page -->
<!-- a padding to disable MSIE and Chrome friendly error page -->

StatusCode: 400
wangluozhe commented 1 year ago

你好像用的是旧版本的requests,更新到1.1.14版本以后即可正常访问。

gospider007 commented 1 year ago

最新版1.1.15 报错

Get "https://www.thelancet.com/": stream error: stream ID 1; PROTOCOL_ERROR; server not authoritative for push with host "www.thelancet.com"
wangluozhe commented 1 year ago

最新版1.1.15 报错

Get "https://www.thelancet.com/": stream error: stream ID 1; PROTOCOL_ERROR; server not authoritative for push with host "www.thelancet.com"

你没有用代理,加上代理试试。我这边加上代理就没问题了。

gospider007 commented 1 year ago

为啥要用代理?这个网站并不需要翻墙就能访问。下面是我用python 正常访问的代码

import requests
a=requests.get("https://www.thelancet.com/")
print(a.text)

image