在本地主机
问题描述:
运行(400)错误的请求错误asp.net网站我设计的Facebook的数据访问一个网站,当我在本地主机访问它:4999端口,但是当曾经在页面加载,然后错误出现在本地主机
public class FacebookLoginHelper
{
public Dictionary<string,> GetAccessToken(string code, string scope,string redirectUrl)
{
Dictionary<string,> tokens = new Dictionary<string,>();
string clientId = FacebookApplication.Current.AppId;
//FacebookContext.Current.AppId;
string clientSecret = FacebookApplication.Current.AppSecret;
string url = string.Format("https://graph.facebook.com/oauth/access_token?client_id={0}&redirect_uri={1}&client_secret={2}&code={3}&scope={4}",
clientId, redirectUrl, clientSecret, code, scope);
HttpWebRequest request = WebRequest.Create(url) as HttpWebRequest;
using (HttpWebResponse response = request.GetResponse() as HttpWebResponse)
{
StreamReader reader = new StreamReader(response.GetResponseStream());
string retVal = reader.ReadToEnd();
foreach (string token in retVal.Split('&'))
{
tokens.Add(token.Substring(0, token.IndexOf("=")),
token.Substring(token.IndexOf("=") + 1, token.Length - token.IndexOf("=") - 1));
}
}
return tokens;
}
}
现在它示出了在线路错误400: 使用(HttpWebResponse响应= request.GetResponse()作为HttpWebResponse)
的原因是什么?请帮助我?
感谢
答
400错误请求错误是由Facebook的API返回时的参数之一是无效的,你现在要做的请求,你可以尝试手动粘贴在您的浏览器所请求的URL与参数一起,它应该显示错误的原因为JSON(在Chrome或Firefox),像这样的例子:
{
"error": {
"type": "OAuthException",
"message": "redirect_uri isn't an absolute URI. Check RFC 3986."
}
从这一点上,你可以检查出了什么问题并解决它。