-2
내 응용 프로그램에서는 AFNetworking을 사용하여 서비스를 구문 분석합니다. 여기에 서버에 이미지를 게시해야하므로 이미지를 게시하려 할 때 오류 메시지 아래에 응답으로 표시됩니다. 여기 AFNetworking을 사용하여 이미지를 게시하는 방법은 무엇입니까?
내 코드입니다 :NSString *urlString = [NSString stringWithFormat:@"http://www.xyz.com:8084/TappyokaCmsService/Service.svc"];
NSString *path=[NSString stringWithFormat:@"/InsertUserInfo?User_Name=%@&User_Pwd=%@&User_FName=%@&User_LName=%@&User_Mail=%@&User_Phno=%@&User_Address=%@&User_Dob=%@&Ic_No=%@&User_Active=%@&User_Questions=%@&User_Ans=%@&ImageUrl=%@&IsSocial=%@",@"skull",@"skull",@"skull",@"skull",@"skull",@"skull",@"skull",@"skull",@"skull",@"10001",@"skull",@"skull",@"",@"10001"];
AFHTTPClient *httpClient= [AFHTTPClient clientWithBaseURL:[NSURL URLWithString:urlString]]; [httpClient registerHTTPOperationClass:[AFJSONRequestOperation class]]; [AFJSONRequestOperation addAcceptableContentTypes:[NSSet setWithObject:@"text/html"]]; NSMutableURLRequest *request = [httpClient multipartFormRequestWithMethod:@"POST" path:path parameters:nil constructingBodyWithBlock:^(id<AFMultipartFormData> formData) {
[formData appendPartWithFileData:imageToUpload name:@"skull" fileName:@"skull.jpg" mimeType:@"image/jpg"];
}];
// You can add then the progressBlock and the completionBlock
AFHTTPRequestOperation *operation = [[AFHTTPRequestOperation alloc] initWithRequest:request];
[operation setCompletionBlockWithSuccess:^(AFHTTPRequestOperation *operation, id responseObject)
{
NSDictionary *jsons = [NSJSONSerialization JSONObjectWithData:responseObject options:kNilOptions error:nil];
NSLog(@"response: %@",jsons);
}
failure:^(AFHTTPRequestOperation *operation, NSError *error)
{
if([operation.response statusCode] == 403)
{
NSLog(@"Upload Failed");
return;
}
NSLog(@"error: %@", [operation error]);
}];
[operation start];
그리고 오류 메시지는 다음과 같습니다
Status code: 404, headers {
"Content-Length" = 1245;
"Content-Type" = "text/html";
Date = "Wed, 20 Nov 2013 15:04:17 GMT";
Server = "Microsoft-IIS/7.5";
"X-Powered-By" = "ASP.NET"
클리어리 plz를 설명 할 수 있습니까? – user2230971
@ user2230971 내 대답을 편집했지만, 내가 가진 것보다 훨씬 명확하게 말할 수는 없습니다. – NinjaLikesCheez