我想將圖像上傳到服務器。服務器的服務是用.NET編寫的。現在服務器要求我發送圖像作爲數據字節不是multipart.I上傳文件由下面的代碼。我得到的響應文件上傳,但圖像不顯示。上傳文件到服務器沒有multipart在目標c?
[request setURL:[NSURL URLWithString:url]];
[request setHTTPMethod:@"POST"];
NSMutableData *body = [NSMutableData data];
NSString *boundary = @"---------------------------14737809831466499882746641449";
//NSString *contentType = [NSString stringWithFormat:@"multipart/form-data; boundary=%@",boundary];
//[request addValue:contentType forHTTPHeaderField: @"Content-Type"];
[body appendData:[[NSString stringWithFormat:@"--%@\r\n", boundary] dataUsingEncoding:NSUTF8StringEncoding]];
[body appendData:[@"Content-Disposition: form-data; name=\"host_pic\"; filename=\"parkN.png\"\r\n" dataUsingEncoding:NSUTF8StringEncoding]];
[body appendData:[@"Content-Type: application/octet-stream\r\n\r\n" dataUsingEncoding:NSUTF8StringEncoding]];
[body appendData:postData];
[body appendData:[@"\r\n" dataUsingEncoding:NSUTF8StringEncoding]];
// close form
[body appendData:[[NSString stringWithFormat:@"--%@--\r\n", boundary] dataUsingEncoding:NSUTF8StringEncoding]];
// setting the body of the post to the reqeust
[request setHTTPBody:body];
請解釋可能是什麼問題。我該如何上傳這樣的文件。
檢查這個答案:http://stackoverflow.com/a/7289185/4831524 –
那麼如何發送的字節數組server.Can請您更新mycode的? – iOSGuy
爲檢查這個答http://stackoverflow.com/a/38263070/4831524 –