Github上的OAuth:远程服务器返回禁止错误(403) [英] Github OAuth : The remote server returned an error (403) Forbidden
问题描述
我已经成功地接收的access_token
,浏览到 https://api.github.com/user?access_token=ACCESS_TOKEN_HERE
工作得很好,浏览器显示我的所有信息。
但是,当我试图用ASP.NET(C#)来获取这些信息,我得到一个错误:
远程服务器返回禁止错误(403)
块引用>
下面是我用来使一个GET请求代码。
WebRequest的要求= WebRequest.Create(https://api.github.com/user?access_token=+的access_token);
request.Method =GET;
WebResponse的响应= request.GetResponse(); //错误在这里,
流数据流= response.GetResponseStream();
StreamReader的读者=新的StreamReader(数据流);
字符串结果= reader.ReadToEnd();
解决方案我监视我的Firefox的请求和响应,当我直接访问URL(工作)。我不得不设置正确的内容类型。我增加了以下和一切工作
request.UserAgent =富;
request.Accept =应用/ JSON;
I've managed to receive the
access_token
, browsing tohttps://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();
解决方案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";
这篇关于Github上的OAuth:远程服务器返回禁止错误(403)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!