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:[メッセージdataUsingEncoding:NSUTF8StringEncoding]]; [request addValue:@ "application / xml; charset = utf-8" forHTTPHeaderField:@ "Content-Type"];
コードのこの部分は正しいですか?