我試圖從Visual Studio訪問Salesforce數據。但是代碼返回上述異常。 我的課堂文件如下。在System.dll中發生類型'System.Net.WebException'的異常,但未在用戶代碼中處理
public string HttpPost(string URI, string Parameters)
{
System.Net.WebRequest req = System.Net.WebRequest.Create(URI);
req.ContentType = "application/x-www-form-urlencoded";
req.Method = "POST";
// Add parameters to post
byte[] data = System.Text.Encoding.ASCII.GetBytes(Parameters);
req.ContentLength = data.Length;
System.IO.Stream os = req.GetRequestStream();
os.Write(data, 0, data.Length);
os.Close();
// Do the post and get the response.
**System.Net.WebResponse resp = req.GetResponse();**
if (resp == null) return null;
System.IO.StreamReader sr = new System.IO.StreamReader(resp.GetResponseStream());
return sr.ReadToEnd().Trim();
}
我想調用POST方法從salesforce中檢索令牌。 '**'所包含的聲明會引發異常。
The remote server returned an error: (400) Bad Request.
任何幫助表示讚賞。
捕獲異常並查看響應正文,它將獲得有關請求失敗原因的更多信息。除非您提供您正在使用的URI和params值,否則很難說更多關於它爲什麼可能不起作用的問題。 – superfell