获得“握手失败...意外的分组格式”当使用WebClient.UploadFile()与“https”当服务器具有有效的SSL证书时 [英] Getting "Handshake failed...unexpected packet format" when using WebClient.UploadFile() with "https" when the server has a valid SSL certificate

查看:332
本文介绍了获得“握手失败...意外的分组格式”当使用WebClient.UploadFile()与“https”当服务器具有有效的SSL证书时的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想使用WebClient.UploadFile与HTTPS URL,但我与

I am trying to use WebClient.UploadFile with a HTTPS URL but I am ending up with

System.IO.IOException:握手失败,因为一个意想不到的
包格式为

"System.IO.IOException: The handshake failed due to an unexpected packet format"

同样的代码使用完全正常的Http但服务器,我我试图打有一个完全正常的SSL证书。下面是有关什么网络电话:

The same code works perfectly fine with Http but the server that I am trying to hit has a perfectly fine ssl certificate. Here is anything relevant to the web call:

var url = WebServiceCommunication.GetProtocolName() + "..."; //turns out to be     "https://...
var wc = new WebClient();
//I am adding: 
wc.Headers.Add(HttpRequestHeader.KeepAlive, "...")
wc.Headers.Add(HttpRequestHeader.AcceptLanguage, "...")
we.Headers.Add(HttpRequestHeader.Cookie, "...")

wc.UploadFile(url, "POST", filename);

是问题与任何HttpRequestHeaders我添加和使用https有那些?还是我缺少一个必要的头,如果我想使用https的?有没有人有任何指针,为什么这将与HTTP工作,但没有使用https当SSL证书是有效的?

Is the issue with any of the HttpRequestHeaders I am adding AND using https with those? Or am I missing a necessary header if I want to use https? Does anyone have any pointers as to why this would work with HTTP but NOT HTTPS when the SSL cert is valid?

推荐答案

您必须确保您areconneting的端口是443,而不是80端口。

You have to make sure the port you areconneting to is port 443 instead of port 80.

的explictely设置端口在URL中使用示例:

Example of explictely setting the port to be used in the url:

var request = (HttpWebRequest) WebRequest.Create("https://example.com:443/");
request.Method = "GET";
request.UserAgent = "example/1.0";
request.Accept = "*/*";
request.Host = "example.com";

var resp = (HttpWebResponse) request.GetResponse();

这篇关于获得“握手失败...意外的分组格式”当使用WebClient.UploadFile()与“https”当服务器具有有效的SSL证书时的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆