2011-02-27 67 views
3

我有以下代碼將圖像上傳到網站。NSURLConnection NSMutableURLRequest和HTTPS

[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失敗與

錯誤:錯誤域= NSURLErrorDomain代碼= -1005「網絡連接丟失」 UserInfo = 0x1c7f70 {NSErrorFailingURLStringKey = https:.......

它與之通信的服務器是MS Server 2008 R2。

任何想法,將不勝感激。

Neil。

+0

此外,服務器運行IIS與ASP.Net 4。 – 2011-02-27 14:42:48

回答

相關問題