简体   繁体   中英

HttpWebRequest GET throwing 400 bad request

I have an application which is calling an GET API for getting some reports. Here is my code

 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();

I went through plenty of articles and did lot of changes here and there but still i am getting 400 bad request

Just for my curiosity I used a wrong username and password but still I am getting the same error 400 bad request

What is missing or wrong in my request?

There is something wrong with your request, your GET API require more information eg header to process the request. You can find the general causes for the error from here http://www.checkupdown.com/status/E400.html

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM