(400)在本地主机上运行asp.net站点的错误请求错误 [英] (400) Bad Request error running asp.net site at local host
本文介绍了(400)在本地主机上运行asp.net站点的错误请求错误的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
嗨
我设计了一个用于Facebook数据访问的网站.我在localhost:4999端口访问页面时加载页面时出现错误.
Hi
I designed a website for facebook data access. I am getting an error when the page loads while i was accessing it at localhost:4999 port.
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()作为HttpWebResponse)
是什么原因 ?请帮帮我吗?
谢谢
Now it shows error 400 at line :
using (HttpWebResponse response = request.GetResponse() as HttpWebResponse)
What is the reason ? Please help me out ?
Thanks
推荐答案
将您遇到错误的行放在try-catch块中,看看调试时遇到的异常是什么.
Place the line which you are having an error in a try-catch block and see what is the exception you are getting while debugging it.
WebRequest request = WebRequest.Create("url");
try
{
using (WebResponse response = request.GetResponse())
{
Console.WriteLine("Won't get here");
}
}
catch (WebException e)
{
using (WebResponse response = e.Response)
{
HttpWebResponse httpResponse = (HttpWebResponse) response;
Console.WriteLine("Error code: {0}", httpResponse.StatusCode);
using (Stream data = response.GetResponseStream())
{
string text = new StreamReader(data).ReadToEnd();
Console.WriteLine(text);
}
}
}
这篇关于(400)在本地主机上运行asp.net站点的错误请求错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文