远程服务器返回禁止错误

远程服务器返回禁止错误

本文介绍了Github上的OAuth:远程服务器返回禁止错误(403)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已经成功地接收的access_token ,浏览到 https://api.github.com/user?access_token=ACCESS_TOKEN_HERE 工作得很好,浏览器显示我的所有信息。



但是,当我试图用ASP.NET(C#)来获取这些信息,我得到一个错误:



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)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

07-24 11:37