C#WinForms应用程序中的HTTPS(安全)POST问题

时间:2012-03-17 11:42:50

标签: c# winforms https

我在C#中创建一个WinForms应用程序,它使用POST方法向HTTPS网站发送缓冲区。当我在HTTPS下发送数据时,上传的数据会被复制。例如,如果我发送缓冲区您好,则会将 HiHi 发送到服务器。

虽然在正常的HTTP连接下可以正常工作。只有在安全连接下才会出现此问题。

我在发送数据之前在stream-write上设置了一个断点,缓冲区包含正确的数据。为什么它会在HTTPS下发送双重信息?

标题

   POST /login/ HTTP/1.0
   Content-Type: application/x-www-form-urlencoded
   Host: abc.test.com
   Content-Length: 12

   username=bobusername=bob

-

这是我目前使用的代码:

string post_data = "username=bob";

string uri = "https://abc.test.com/login/";

HttpWebRequest request = (HttpWebRequest)
WebRequest.Create(uri); 
request.KeepAlive = false;
request.ProtocolVersion = HttpVersion.Version10;
request.Method = "POST";

byte[] postBytes = Encoding.ASCII.GetBytes(post_data);

request.ContentType = "application/x-www-form-urlencoded";
request.ContentLength = postBytes.Length;

Stream requestStream = request.GetRequestStream();

requestStream.Write(postBytes, 0, postBytes.Length);

MessageBox.Show(postBytes.Length.ToString());
requestStream.Close();

HttpWebResponse response = (HttpWebResponse)request.GetResponse();
StreamReader sr = new StreamReader(response.GetResponseStream());
string tmp = sr.ReadToEnd().Trim();

0 个答案:

没有答案