Why Does my HttpWebRequest Return 400 Bad request?

后端 未结 4 1839
梦毁少年i
梦毁少年i 2020-12-03 15:35

The following code fails with a 400 bad request exception. My network connection is good and I can go to the site but I cannot get this uri with HttpWebRequest.



        
4条回答
  •  遥遥无期
    2020-12-03 16:21

    There could be many causes for this problem. Do you have any more details about the WebException?

    One cause, which I've run into before, is that you have a bad user agent string. Some websites (google for instance) check that requests are coming from known user agents to prevent automated bots from hitting their pages.

    In fact, you may want to check that the user agreement for YouTube does not preclude you from doing what you're doing. If it does, then what you're doing may be better accomplished by going through approved channels such as web services.

提交回复
热议问题