AFNetworking发布并获取xml数据

时间:2014-05-23 07:05:58

标签: ios objective-c afnetworking-2

我想使用afnetworking发布有关此服务的一些数据,其内容类型为application / soap + xml.but我收到了错误

Error Domain=AFNetworkingErrorDomain Code=-1011 "Request failed: internal server error (500)" UserInfo=0x9034f00 {NSErrorFailingURLKey=http://webapp.admin-inapp.com/services/FeedbackService.asmx?op=SendFeedback, AFNetworkingOperationFailingURLResponseErrorKey=<NSHTTPURLResponse: 0x8e31a00> { URL: http://webapp.admin-inapp.com/services/FeedbackService.asmx?op=SendFeedback } { status code: 500, headers {
"Cache-Control" = private;
"Content-Length" = 1666;
"Content-Type" = "application/soap+xml; charset=utf-8";
Date = "Fri, 23 May 2014 06:43:32 GMT";
Server = "Microsoft-IIS/8.0";
"X-AspNet-Version" = "4.0.30319";
"X-Powered-By" = "ASP.NET";

}},NSLocalizedDescription =请求失败:内部服务器错误(500)}

这是我的代码

NSString *string = [NSString stringWithFormat:@"http://webapp.admin-inapp.com/services/FeedbackService.asmx?op=SendFeedback"];
NSMutableDictionary *dict = [[NSMutableDictionary alloc]init];
[dict setObject:@"9888291933" forKey:@"Number"];
[dict setObject:self.textview.text forKey:@"Feedback"];
AFHTTPRequestOperationManager * manager = [AFHTTPRequestOperationManager manager];

[manager POST:string parameters:dict success:^(AFHTTPRequestOperation *operation, id responseObject) {
    NSLog(@"%@",responseObject);
} failure:^(AFHTTPRequestOperation *operation, NSError *error) {
    NSLog(@"%@",error);
}];

}

1 个答案:

答案 0 :(得分:0)

请检查您的网址和对象。

我认为这是SOAP Web服务。您必须以不同方式发送SOAP Web服务请求。

NSString *soapMessage = [NSString stringWithFormat:
                     @"<?xml version=\"1.0\" encoding=\"utf-8\"?>\n"
                     "<soap:Envelope xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\" xmlns:xsd=\"http://www.w3.org/2001/XMLSchema\" xmlns:soap=\"http://schemas.xmlsoap.org/soap/envelope/\">\n"
                     "<soap:Body>\n"
                     "<YourServiceName xmlns=\"http://tempuri.org/\">\n"
                     "<Number>1001010</Number>\n"
                     "<Feedback>Something feedback</Feedback>\n"
                     "</YourServiceName>\n"
                     "</soap:Body>\n"
                     "</soap:Envelope>\n", Number, Feedback
                     ];

                     NSURL *url = [NSURL URLWithString:@"http://webapp.admin-inapp.com/services/FeedbackService.asmx?op=SendFeedback"];
                    NSMutableURLRequest *theRequest = [NSMutableURLRequest     requestWithURL:url];
                   NSString *msgLength = [NSString stringWithFormat:@"%d", [soapMessage length]];
                 [theRequest addValue: @"text/xml; charset=utf-8" forHTTPHeaderField:@"Content-Type"];
   [theRequest addValue: [NSString stringWithFormat:@"http://tempuri.org/%@",service] forHTTPHeaderField:@"SOAPAction"];
   [theRequest addValue: msgLength forHTTPHeaderField:@"Content-Length"];
  [theRequest setHTTPMethod:@"POST"];
 [theRequest setHTTPBody: [soapMessage dataUsingEncoding:NSUTF8StringEncoding]];
[theRequest setTimeoutInterval:10];
 NSURLConnection *theConnection = [[NSURLConnection alloc] initWithRequest:theRequest delegate:self];

if( theConnection )
{
 responseData = [[NSMutableData data] retain];
}
else
 {
NSLog(@"theConnection is NULL");
 }