我有用post方法xmlparsing的问题。xml使用Post方法解析+ iphone
API URL : http://XXX.XXX.X.XX/api/user.php
Function Name : getUserList
Sample XML :
<root>
<data>
<id>0</id>
<search></search>
</data>
</root>
我现在用: -
// setting up the URL to post to
NSString *urlString = @"http://XXX.XXX.X.XX/api/user.php";
// setting up the request object now
NSMutableURLRequest *request = [[[NSMutableURLRequest alloc] init] autorelease];
[request setURL:[NSURL URLWithString:urlString]];
[request setHTTPMethod:@"POST"];
但我要如何在这后HTMLbody部分..
指,我应该如何把功能名称和示例XML中代码
我编辑的问题是: -
NSString *urlString = @" http://192.168.6.79/silverAPI/api/user.php/getUserList";
// setting up the request object now
NSMutableURLRequest *request = [[[NSMutableURLRequest alloc] init] autorelease];
[request setURL:[NSURL URLWithString:urlString]];
[request setHTTPMethod:@"POST"];
NSString * str = @"<root><data><id>0</id><search>a</search></data></root>";
NSString * message= [NSString stringWithFormat:@"/getUserList mydata=%@", str];
[request setHTTPBody:[message dataUsingEncoding:NSUTF8StringEncoding]];
[request addValue:@"application/xml; charset=utf-8" forHTTPHeaderField:@"Content-Type"];
// now lets make the connection to the web
NSData *returnData = [NSURLConnection sendSynchronousRequest:request returningResponse:nil error:nil];
NSString *returnString = [[NSString alloc] initWithData:returnData encoding:NSUTF8StringEncoding];
NSLog(@"Responce==>%@",returnString);
但我越来越黑responce.Pleaseee帮我.. 是我
NSString *urlString = @" http://192.168.6.79/silverAPI/api/user.php/getUserList";
而且
NSString * str = @"0a"; NSString * message= [NSString stringWithFormat:@"/getUserList mydata=%@", str]; [request setHTTPBody:[message dataUsingEncoding:NSUTF8StringEncoding]]; [request addValue:@"application/xml; charset=utf-8" forHTTPHeaderField:@"Content-Type"];
这部分代码是正确的?
感谢您的快速回复。可以给我这个想法,我应该如何获得响应数据。我使用过这个。请指导我是否正确:-NSData * returnData = [NSURLConnection sendSynchronousRequest:request returningResponse:nil error :零]; \t NSString * returnString = [[NSString alloc] initWithData:returnData encoding:NSUTF8StringEncoding]; –
它看起来不错,但为什么你不想检查返回的响应代码? – Nekto
我想检查性反应的即时得到throigh这是否是正确的或不 –