嗨這工作時發佈到http地址,但發佈到HTTPS地址發佈失敗,無法建立信任關係!c#.net4 webRequest通過SSL不起作用
我需要做些什麼或這是一個服務器錯誤!?
private static string HttpPost (string uri, string parameters)
{
//return "ok";
// parameters: name1=value1&name2=value2
try
{
WebRequest webRequest = WebRequest.Create(uri);
webRequest.ContentType = "application/x-www-form-urlencoded";
webRequest.Method = "POST";
byte[] bytes = Encoding.ASCII.GetBytes(parameters);
Stream os = null;
try
{ // send the Post
webRequest.ContentLength = bytes.Length; //Count bytes to send
os = webRequest.GetRequestStream();
os.Write(bytes, 0, bytes.Length); //Send it
}
catch (WebException ex)
{
MessageBox.Show(ex.Message, "HttpPost: Request error",
MessageBoxButtons.OK, MessageBoxIcon.Error);
}
finally
{
if (os != null)
{
os.Close();
}
}
try
{ // get the response
WebResponse webResponse = webRequest.GetResponse();
if (webResponse == null)
{ return null; }
StreamReader sr = new StreamReader(webResponse.GetResponseStream());
return sr.ReadToEnd().Trim();
}
catch (WebException ex)
{
MessageBox.Show(ex.Message, "HttpPost: Response error",
MessageBoxButtons.OK, MessageBoxIcon.Error);
}
}
catch
{
}
return null;
} // end HttpPost
你說它失敗了......你有什麼異常?如果您在瀏覽器中訪問https站點,它是否正常工作? – Nik 2010-09-14 20:04:10
BTW:您使用HttpWebRequest而不是[WebClient](http://msdn.microsoft.com/en-us/library/system.net.webclient.aspx)[.UploadValues](http:// msdn .microsoft.com/EN-US /庫/ 9w7b4fz7.aspx)? – dtb 2010-09-14 20:05:52
嗨例外是: – Adrian 2010-09-14 20:14:23