【问题标题】:HttpWebRequest GET throwing 400 bad requestHttpWebRequest GET 抛出 400 错误请求
【发布时间】:2015-11-05 09:52:45
【问题描述】:

我有一个应用程序正在调用 GET API 来获取一些报告。 这是我的代码

 HttpWebRequest myHttpWebRequest = null;     
 HttpWebResponse myHttpWebResponse = null;

myHttpWebRequest = (HttpWebRequest)HttpWebRequest.Create("https://cybersource.com/DownloadReport/2015/11/04/profile/TransactionDetailReport.xml");

myHttpWebRequest.Method = "GET";
myHttpWebRequest.ContentType = "text/xml; encoding='utf-8'";

string authInfo = "username:password";
authInfo = Convert.ToBase64String(Encoding.Default.GetBytes(authInfo));
myHttpWebRequest.Headers.Add("Authorization", "Basic " + authInfo);

myHttpWebResponse = (HttpWebResponse)myHttpWebRequest.GetResponse();

我浏览了很多文章并在这里和那里做了很多更改,但我仍然收到400 bad request

出于好奇,我使用了错误的用户名和密码,但我仍然收到同样的错误400 bad request

我的请求中缺少什么或错误?

【问题讨论】:

标签: c# asp.net get httpwebrequest


【解决方案1】:

您的请求有问题,您的 GET API 需要更多信息,例如标头来处理请求。您可以从这里找到错误的一般原因http://www.checkupdown.com/status/E400.html

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2013-10-02
    • 2020-10-28
    • 2020-05-14
    • 1970-01-01
    • 2019-12-02
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多