不能发布文件数据时,请求被发送通过SSL [英] Can't post file data when request is sent over SSL

查看:233
本文介绍了不能发布文件数据时,请求被发送通过SSL的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有问题,尝试使用自定义的基本身份验证模块与此类似。客户端使用的HttpWebRequest 类。

I have problems trying to use custom basic authentication module similar to this. The client uses HttpWebRequest class.

客户端运行以下code:

The client runs the following code:

void uploadFile( string serverUrl, string filePath )
{
    HttpWebRequest request = (HttpWebRequest)HttpWebRequest.
        Create( serverUrl );
    CredentialCache cache = new CredentialCache();
    cache.Add( new Uri( serverUrl ), "Basic", new NetworkCredential( "User", "pass" ) );
    request.Credentials = cache;
    request.Method = "POST";
    request.ContentType = "application/octet-stream";
    request.Timeout = 60000;
    request.KeepAlive = true;

    using( BinaryReader reader = new BinaryReader( 
        File.OpenRead( filePath ) ) ) {

        request.ContentLength = reader.BaseStream.Length;
        using( Stream stream = request.GetRequestStream() ) {
            byte[] buffer = new byte[1024];
            while( true ) {
                int bytesRead = reader.Read( buffer, 0, buffer.Length );
                if( bytesRead == 0 ) {
                    break;
                }
                stream.Write( buffer, 0, bytesRead );
            }
        }
    }

     HttpWebResponse result = (HttpWebResponse)request.GetResponse();
     //handle result - not relevant
 }

如果请求的URI开始创建HTTP:// 它工作正常 - 请求到达服务器,身份验证模块传递请求时,它回答与 WWW验证,请求现在重复认证参数,模块验证它,并将它传递更多。

If the request is created for a URI starting with http:// it works okay - a request reaches the server, the authentication module is passed the request, it replies with WWW-Authenticate, the request is repeated now with authentication parameters, the module validates it and it passes further.

如果请求的URI开始创建的https:// 这是行不通的。在初始请求获取到模块和模块回复与 WWW验证

If the request is created for a URI starting with https:// it doesn't work. The initial request gets to the module and the module replies with WWW-Authenticate

void ReplyWithAuthHeader()
{
    HttpContext currentContext = HttpContext.Current;
    context.Response.StatusCode = 401;
    context.Response.AddHeader( "WWW-Authenticate",
       String.Format("Basic realm=\"{0}\"", "myname.mycompany.com"));
}

这是一个异常被抛出在客户端与无法将数据写入传输连接:一个已建立的连接被中止通过在主机中的软件文本。

an an exception is thrown at the client with "Unable to write data to the transport connection: An established connection was aborted by the software in your host machine." text.

我想 System.Net跟踪并且发现,发送客户端回来下面的头在初始请求后:

I tried System.Net tracing and discovered that after sending the initial request the client gets back the following header:

Date: Fri, 04 Feb 2011 12:15:04 GMT
Server: Microsoft-IIS/5.1
X-Powered-By: ASP.NET

而当URI开始的http:// 收到客户端的以下内容:

while when the URI started with http:// the client received the following:

Content-Length: 1894
Cache-Control: private
Content-Type: text/html; charset=utf-8
Date: Fri, 04 Feb 2011 12:12:11 GMT
Server: Microsoft-IIS/5.1
WWW-Authenticate: Basic realm="myname.mycompany.com"
X-AspNet-Version: 2.0.50727
X-Powered-By: ASP.NET

这么清楚的 WWW验证响应地方咽下去,不会到达客户端。

so clearly the WWW-Authenticate response is swallowed somewhere and doesn't reach the client.

另外,如果我排除code。该文件中的数据写入也没关系验证请求。

Also if I exclude the code that writes the file data into the request it also authenticates okay.

我该如何解决这个问题?如何让我的 WWW验证响应到达客户端?

How do I fix this? How do I make the WWW-Authenticate response get to the client?

推荐答案

什么是CS服务器返回的HTTP状态$ C $? 是服务器的证书是否有效? 你能后的堆栈跟踪?

What are the http status codes returned from the server? Is the certificate of the server valid? Can you post the stack trace?

尝试禁用您的防火墙,就像小提琴手等其他网络工具客户端上。 也可以尝试用KeepAlive属性设置为false。

Try to disable your firewall and other networking tools like fiddler etc on your client. Also try with the KeepAlive property to false.

这篇关于不能发布文件数据时,请求被发送通过SSL的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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