HttpWebRequest returns “ (403) Forbidden” Error

前端 未结 5 1524
醉酒成梦
醉酒成梦 2021-01-11 17:11

I wrote a xml grabber to receive/decode xml files from website. It works fine mostly but it always return error:

\"The remote server returned an e

5条回答
  •  耶瑟儿~
    2021-01-11 18:03

    In my particular case, it was not the UserAgent header, but the Accept header that the server didn't like.

    request.Accept = "text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,image/apng,*/*;q=0.8";
    

    You can use the browsers network tab of dev tools to see what the correct headers should be.

提交回复
热议问题