使用NSURLConnection的iPhone的HTTPS POST会挂起某些文件大小范围 [英] HTTPS POST from iPhone using NSURLConnection hangs for certain filesize range

查看:273
本文介绍了使用NSURLConnection的iPhone的HTTPS POST会挂起某些文件大小范围的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用NSURLConnection对我们的web服务进行异步HTTPS POST以上传jpg。它在大多数情况下工作正常。

I'm using NSURLConnection to make an async HTTPS POST to our webservice to upload a jpg. It works fine most of the time.

但当帖子正文在196609和196868字节(包括)之间时,文件上传100%后连接挂起( didSendBodyData告诉我它是100%发送的)。然后在5分钟后,连接超时,并显示消息网络连接已丢失。更大和更小的文件大小工作。我已经通过限制我添加到帖子正文的文件的文件大小来测试这个。

But when the post body is between 196609 and 196868 bytes (inclusive), the connection hangs after the file has been uploaded 100% (didSendBodyData tells me that it's 100% sent). Then after 5 minutes, the connection times out with the message "The network connection was lost." Larger and smaller filesizes work. I've tested this by capping the filesize of the file that I add to the post body.

内容长度设置正确。请参阅下面的代码。

The content length is getting set correctly. See the code below.

当我通过HTTP上传到netcat时上传看起来很好。消息的整个部分都可以通过。但我怀疑因为SSL加密会出现问题,比如它正在缓冲一个SSL加密的块框架。

The upload looks fine when I upload to netcat via HTTP. The entire body of the message gets through. But I suspect something's going wrong because of the SSL encryption, like it's buffering an SSL encrypted block frame.

iPhone的SSL代码中是否有一个错误导致它无法上传整个邮政机构即使报告它是,或其他什么?

Is there a bug in the iPhone's SSL code that makes it not upload the entire post body even though it's reporting that it is, or something else?

这是我设置内容长度并将文件附加到多部分POST主体的部分。您可以看到我手动限制文件大小以进行测试。

Here's the section where I set the content length and append the file to the multi-part POST body. You can see i'm capping the filesize manually, to test.

NSMutableURLRequest *request = [NSMutableURLRequest requestWithURL:nsurl];
[request setHTTPMethod:@"POST"];
[request setTimeoutInterval:1];
[request addValue:@"close" forHTTPHeaderField: @"Connection"];

// Add headers and POST information
NSLog( @"Posting file." );
NSString *stringBoundary = [NSString stringWithString:@"0xKhTmLbOuNdArY"];
NSString *contentType = [NSString stringWithFormat:@"multipart/form-data; boundary=%@",stringBoundary];
[request addValue:contentType forHTTPHeaderField: @"Content-Type"];
NSMutableData *postBody = [NSMutableData data];

...

[postBody appendData:[[NSString stringWithFormat:@"--%@\r\n",stringBoundary] dataUsingEncoding:NSUTF8StringEncoding]];
[postBody appendData:[[NSString stringWithString:@"Content-Disposition: form-data; name=\"uploadFile\"; filename=\"upload.jpg\"\r\n"] dataUsingEncoding:NSUTF8StringEncoding]];
[postBody appendData:[[NSString stringWithString:@"Content-Type: image/jpg\r\n\r\n"] dataUsingEncoding:NSUTF8StringEncoding]];
NSLog( @"file size...%d", [uploadFile length] );
//[postBody appendData:uploadFile];
[postBody appendData:[NSData dataWithBytes: [uploadFile bytes] length: 196099]];
[postBody appendData:[[NSString stringWithFormat:@"\r\n--%@--\r\n",stringBoundary] dataUsingEncoding:NSUTF8StringEncoding]];
[request setHTTPBody:postBody];
[request setValue:[NSString stringWithFormat:@"%d", [postBody length]] forHTTPHeaderField:@"Content-Length"];
NSLog(@"Uploaded POST size: %d", [postBody length] );


推荐答案

啊,我发现了问题所在。连接:正在设置保持活动,即使我设置连接:关闭。我该如何覆盖?看起来你不能!?

Ah, I've found what the issue is. Connection: Keep-alive is being set, even though I set connection: close. How do I override this?? It looks like you can't!?

这篇关于使用NSURLConnection的iPhone的HTTPS POST会挂起某些文件大小范围的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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