이미지를 서버에 업로드하고 싶습니다. 서버용 서비스는 .NET으로 작성되었습니다. 이제 서버에서 멀티 파트가 아닌 데이터의 바이트로 이미지를 보내도록 요청합니다. 아래 코드로 파일을 업로드하고 있습니다. 업로드 된 파일은 응답하지만 이미지는 표시되지 않습니다.객관적인 관점에서 파일을 여러 부분없이 서버에 업로드 하시겠습니까?
[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];
문제가 될 수있는 이유를 설명해주세요. 어떻게해야합니까?
검사 ans와 : http://stackoverflow.com/a/7289185/4831524 –
를 그럼 어떻게 당신이 mycode를 업데이트하십시오 server.Can 해당 바이트 배열을 보내? – iOSGuy
해당 내용을 확인하십시오.이 ans http://stackoverflow.com/a/38263070/4831524 –