我有以下上传图像到网站的代码。
[request setURL:nsurl];
[request setHTTPMethod:@"POST"];
NSString *boundary = [NSString stringWithString:@"---------------------------14737809831466499882746641449"];
NSString *contentType = [NSString stringWithFormat:@"multipart/form-data; boundary=%@",boundary];
[request addValue:contentType forHTTPHeaderField: @"Content-Type"];
/*
now lets create the body of the post
*/
NSMutableData *body = [NSMutableData data];
//parameter1
[body appendData:[[NSString stringWithFormat:@"\r\n--%@\r\n",boundary] dataUsingEncoding:NSUTF8StringEncoding]];
[body appendData:[[NSString stringWithFormat:@"Content-Disposition: form-data; name=\"guid\"\r\n\r\n%@", [Settings sharedInstance].uploadID] dataUsingEncoding:NSUTF8StringEncoding]];
[body appendData:[[NSString stringWithFormat:@"\r\n--%@\r\n",boundary] dataUsingEncoding:NSUTF8StringEncoding]];
//Image
[body appendData:[[NSString stringWithFormat:@"Content-Disposition: form-data; name=\"filMyFile\"; filename=\"%@\"\r\n", fileName] dataUsingEncoding:NSUTF8StringEncoding]];
[body appendData:[[NSString stringWithString:@"Content-Type: image/png\r\n\r\n"] dataUsingEncoding:NSUTF8StringEncoding]];
[body appendData:[NSData dataWithData:dataObj]];
[body appendData:[[NSString stringWithFormat:@"\r\n--%@--\r\n",boundary] dataUsingEncoding:NSUTF8StringEncoding]];
// setting the body of the post to the reqeust
[request setHTTPBody:body];
NSURLConnection *connection = [[NSURLConnection alloc] initWithRequest:request delegate:self];在HTTP上运行时,一切都很好,但当我切换到HTTPS时,它会失败,如下所示
错误:错误Domain=NSURLErrorDomain代码=-1005“网络连接丢失。”UserInfo=0x1c7f70 {NSErrorFailingURLStringKey=https:.......
它与之通信的服务器是MS Server2008 R2。
任何想法都将不胜感激。
尼尔。
发布于 2011-11-30 17:09:28
请参阅使用https连接http://developer.apple.com/library/mac/#documentation/Cocoa/Conceptual/URLLoadingSystem/Tasks/UsingNSURLConnection.html的NSURLConnection
https://stackoverflow.com/questions/5133799
复制相似问题