从iphone将XML数据发布到Web服务器 [英] Post XML data to web server from iphone

查看:112
本文介绍了从iphone将XML数据发布到Web服务器的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想以下列格式发布xml数据:

i want to post xml data in following format:

  <?xml version="1.0" encoding="UTF-8"?>    
                       <data>                                               
                         <email>xyz@domain.com</email>
                                 <password>xyz123</password>                                      
                       </data>

并从网络服务器接收以下格式

and receive in following format from the webserver

<?xml version="1.0" encoding="UTF-8"?>    
            <user>
                          <user_id>12</user_id> 

                 </user>

帮助是欣赏
现在我正在尝试使用NSUrlConnection和NSMutableRequest
i can在名称上发布数据,如表格帖子,但我想发布只是xml数据。
我也尝试过使用ASIHTTPRequest。
任何代码或链接都是高度适用的。

help is appreciate now i am trying to use NSUrlConnection and NSMutableRequest i can post data on name like form post,but i want to post just xml data. i have also tried to used ASIHTTPRequest . any code or link is highly appriciated.

推荐答案

最后我使用了来自 http://allseeing-i.com/ASIHTTPRequest/

并发布来自以下代码:

NSURL *url = [NSURL URLWithString:@"http://url to post data"];
    ASIFormDataRequest *request = [ASIFormDataRequest requestWithURL:url];
    [request addPostValue:@"test name" forKey:@"name"];

    [request setDelegate:self];
    [request startSynchronous];

并使用委托方法接收数据或错误。

and used delegate method to receive data or error.

- (void)requestFinished:(ASIHTTPRequest *)request
{
    // Use when fetching text data
    NSString *responseString = [request responseString];
    NSLog(@"%@",responseString);

    // Use when fetching binary data
    NSData *responseData = [request responseData];
}

- (void)requestFailed:(ASIHTTPRequest *)request
{
    NSError *error = [request error];
    NSLog(@"Error %@",error);
}

这篇关于从iphone将XML数据发布到Web服务器的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆