Github OAuth : The remote server returned an error (403) Forbidden

筅森魡賤 提交于 2019-12-08 02:11:18

问题


I've managed to receive the access_token, browsing to https://api.github.com/user?access_token=ACCESS_TOKEN_HERE works very well and the browser displays all my information.

But when I'm trying to get these information with ASP.NET (C#), I get an error:

The remote server returned an error (403) Forbidden.

Here is the code I'm using to make an Get Request.

WebRequest request = WebRequest.Create("https://api.github.com/user?access_token=" + access_token);
request.Method = "GET";
WebResponse response = request.GetResponse(); //Error Here
Stream dataStream = response.GetResponseStream();
StreamReader reader = new StreamReader(dataStream);
string result = reader.ReadToEnd();

回答1:


I monitored the request and response in my Firefox when I directly access the URL (which works). I had to set the right content type. I added the following and everything worked.

request.UserAgent = "Foo";
request.Accept = "application/json";


来源:https://stackoverflow.com/questions/21978125/github-oauth-the-remote-server-returned-an-error-403-forbidden

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!