2015-11-05 55 views
0

我有一個應用程序正在調用GET API來獲取一些報告。 這裏是我的代碼HttpWebRequest GET拋出400個不好的請求

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

什麼是缺少或錯誤在我的要求?

+0

http://stackoverflow.com/questions/692342/net-httpwebrequest-getresponse-raises-exception-when-http-status-code-400-ba –

+0

可能複製http://stackoverflow.com/questions/23054960/getresponse-throws-400-bad-request –

+0

不,它沒有幫助,因爲錯誤流顯示我「出了點問題」 – smilu

回答