我有一點問題。 我必須使用POST方法將我的iPhone上的照片上傳到Web服務器,但服務器文件在aspx中。 我用我的服務器和PHP文件試過我的代碼:效果很好! 現在有了aspx文件:不會上傳:(iPhone:將圖片上傳到網頁aspx文件
我到.aspx不havec訪問
這裏是我的iphone代碼:
NSData *imageData = UIImageJPEGRepresentation(imageView.image,70);
NSString *urlString = @"http://iphone.domain.net/upload_photos.aspx";
NSMutableURLRequest *request = [[[NSMutableURLRequest alloc] init] autorelease];
[request setURL:[NSURL URLWithString:urlString]];
[request setHTTPMethod:@"POST"];
NSString *boundary = [NSString stringWithString:@"---------------------------14737809831466499882746641449"];
NSString *contentType = [NSString stringWithFormat:@"multipart/form-data; boundary=%@",boundary];
[request addValue:contentType forHTTPHeaderField: @"Content-Type"];
NSMutableData *body = [NSMutableData data];
[body appendData:[[NSString stringWithFormat:@"--%@\r\n",boundary] dataUsingEncoding:NSUTF8StringEncoding]];
[body appendData:[[NSString stringWithFormat:@"Content-Disposition: form-data; name=\"photo\"; filename=\"%@.jpg\"\r\n",[c nom]] dataUsingEncoding:NSUTF8StringEncoding]];
[body appendData:[[NSString stringWithString:@"Content-Type: application/octet-stream\r\n\r\n"] dataUsingEncoding:NSUTF8StringEncoding]];
[body appendData:[NSData dataWithData:imageData]];
[body appendData:[[NSString stringWithFormat:@"\r\n--%@--\r\n",boundary] dataUsingEncoding:NSUTF8StringEncoding]];
[request setHTTPBody:body];
我認爲這個問題是來自在Content-Type或爲我dataUsingEncoding:?參數 你有想法,並解決它
順便說一句,你確定的ASPX工作擺在首位,與你路過此地的確切參數? – mvds 2010-07-29 19:39:18
,你能指定'[c nom]'中的內容嗎? – mvds 2010-07-29 19:40:38
[c nom]是正確的NSString命名我的文件「%@。jpg」 我不知道aspx文件我不能看看它:( – Pierre 2010-07-29 19:48:06