(400) 在本地主机上运行 ASP.NET 站点时发生错误请求错误
我设计了一个用于 facebook 数据访问的网站,当我在 localhost: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 response = request.GetResponse() as HttpWebResponse)
原因是什么?请帮帮我吗?
谢谢
I am designed a website for facebook data access and while i was accessing it at localhost:4999 port but when ever the page loads then error comes
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;
}
}
Now it shows error 400 at line :
using (HttpWebResponse response = request.GetResponse() as HttpWebResponse)
What is the reason ? Please help me out ?
Thanks
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
当其中一个参数对于您尝试执行的请求无效时,Facebook API 将返回 400 Bad Request 错误,您可以尝试将请求的 URL 与参数一起手动粘贴到浏览器上,它应该显示错误原因为 JSON(在 Chrome 或 Firefox 上),例如:
从那时起,您可以检查问题所在并修复它。
A 400 Bad Request Error is returned by the Facebook API when one of the parameters isn't valid for the request you're trying to do, you could try manually pasting the requested URL on your browser along with the parameters, it should display the reason of the error as a JSON (On Chrome or Firefox), Something like this for example:
From that point on, you can check what's wrong and fix it.