通过Web服务iphone问题发布xml数据

时间:2011-06-03 11:40:12

标签: iphone objective-c

这是我的xml

NSString *Message = [NSString stringWithFormat:                      
                         @"<?xml version=\"1.0\" encoding=\"utf-8\"?>\n"
                         "<query>\n"
                         "<IdCategory>1088</IdCategory>\n"
                         "</query>\n"];



NSURL *url = [NSURL URLWithString:@"http://bvd.vndsupport.com/_ws/api/categories/index.asp"];
NSMutableURLRequest *theRequest = [NSMutableURLRequest requestWithURL:url];
NSString *msgLength = [NSString stringWithFormat:@"%d", [Message length]];

[theRequest addValue: @"text/xml; charset=utf-8" forHTTPHeaderField:@"Content-Type"];
[theRequest addValue: msgLength forHTTPHeaderField:@"Content-Length"];
[theRequest setHTTPMethod:@"POST"];
[theRequest setHTTPBody: [Message dataUsingEncoding:NSUTF8StringEncoding]];

NSString *returnString = [[NSString alloc] initWithData:[NSURLConnection sendSynchronousRequest:theRequest returningResponse:nil error:nil] encoding:NSUTF8StringEncoding];
NSLog(@"%@",returnString);

我只是传递此类别ID并获得结果,但returnString始终显示所有类别详细信息。我没有得到确切的结果。这是将xml数据传递给webservice的正确方法吗?

2 个答案:

答案 0 :(得分:3)

去搜索'wsdl2objc',如果你想做肥皂请求,它会为你完成所有工作。

答案 1 :(得分:1)

此代码将完美运行。问题是webservice页面