我在使用 post 方法进行 xmlparsing 时遇到问题。
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);
但我得到了回应。请帮帮我..是我的
NSString *urlString = @" http://192.168.6.79/silverAPI/api/user.php/getUserList";
和
NSString * str = @"0a"; NSString * message= [NSString stringWithFormat:@"/getUserList mydata=%@", str]; [请求setHTTPBody:[消息数据使用编码:NSUTF8StringEncoding]];[请求 addValue:@"application/xml; charset=utf-8" forHTTPHeaderField:@"Content-Type"];
这部分代码是正确的??