-
Notifications
You must be signed in to change notification settings - Fork 117
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
如果在服务端处理视频文件下载,如何跳过403的限制 #38
Comments
设置下header中的 referer 和 host |
🧑🎤 可以例举下 这个两个参数具体设置什么值吗 |
Closed
package main
import (
"fmt"
"io"
"log"
"net/http"
"os"
)
func main() {
mp4Url := "https://f.video.weibocdn.com/u0/xxx.mp4"
client := &http.Client{}
req, err := http.NewRequest("GET", mp4Url, nil)
if err != nil {
log.Fatalln(err)
}
// 根据自己需要下载的网站调整Referer值, 个别网站无需设置也可
req.Header.Set("Referer", "https://weibo.com")
resp, err := client.Do(req)
if err != nil {
log.Fatalln(err)
}
defer resp.Body.Close()
fmt.Println(resp.StatusCode)
if resp.StatusCode != 200 {
log.Fatalf("status code not ok: %d\n", resp.StatusCode)
}
respBody, err := io.ReadAll(resp.Body)
if err != nil {
log.Fatalln(err)
}
err = os.WriteFile("weibo_test.mp4", respBody, os.ModePerm)
if err != nil {
log.Fatalln(err)
}
} 上面以下载微博视频举例, 其他类似 |
感谢大佬 |
Closed
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
我想实现视频下载的功能,发现直接请求视频地址的话会403
The text was updated successfully, but these errors were encountered: