我有用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這是否是正確的或不 –