首页 新闻 赞助 找找看

IOS WebService 接口调用 POST

0
悬赏园豆:100 [待解决问题]

webservice的服务器,提供给IOS接口,里面涉及到POST传智请求,无法获取数据。

服务器端数据可以在浏览器中查看得到。但是在IOS端无法获取,希望各位前辈可以指点一下,跪谢(PS:已经搞了4天了,各种百度,就是获取不了)同时希望各位可以为我提供一个可以在线查看NSDATA格式化的工具:

上代码:

-(void)JXXMLData{

    NSString *Str = [NSStringstringWithFormat:@"<?xml version=\"1.0\" encoding=\"utf-8\"?> \n"

                     "<soap12:Envelope xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\" xmlns:xsd=\"http://www.w3.org/2001/XMLSchema\" xmlns:soap12=\"http://www.w3.org/2003/05/soap-envelope\">"

                     "<soap12:Body>"

                     "<GetVideoList xmlns=\"http://tempuri.org/\">"

                     "<PageSize>%@</PageSize>"

                     "<PageIndex>%@</PageIndex>"

                     "</GetVideoList>"

                     "</soap12:Body>"

                     "</soap12:Envelope>",[NSStringstringWithFormat:@"%d",4],[NSStringstringWithFormat:@"%d",1]];

    NSString *XMLURL = [NSStringstringWithFormat:@"http://X.XX.X.XXX:8081//Videos_Webservice.asmx/GetVideoList"];

    NSURL *url = [NSURLURLWithString:XMLURL];

    NSMutableURLRequest *req = [NSMutableURLRequestrequestWithURL:url];

    NSString *length = [NSStringstringWithFormat:@"%lu",(unsignedlong)[Str length]];

    [req setHTTPMethod:@"POST"];

    [req addValue:@"text/xml; charset=utf-8"forHTTPHeaderField:@"Content-Type"];

    [req addValue:length forHTTPHeaderField:@"Content-Length"];

    [req setHTTPBody:[Str dataUsingEncoding:NSUTF8StringEncoding]];

    NSURLConnection *theConn = [[NSURLConnectionalloc] initWithRequest:req delegate:self];

    if (theConn) {

        NSLog(@"成功");

        _webdata = [NSMutableDatadata];

    }else {

        NSLog(@"失败");

    }

}

//接收到数据的代理

- (void)connection:(NSURLConnection *)connection didReceiveResponse:(NSURLResponse *)response {

    NSLog(@"1");

}

- (void)connection:(NSURLConnection *)connection didReceiveData:(NSData *)data {

    NSLog(@"%@", data); //数据请求成功////////希望可以有NSDATA在线格式化工具 ,一遍查看是否请求到的数据是自己想要的数据

    NSString *aString = [[NSStringalloc] initWithData:data encoding:NSUTF8StringEncoding];

       NSLog(@"%@", aString);//得到想要的XML字符串然后解析,目前这个转换为空!!!

}

如果有这种IOS请求webservice的DEMO,希望可以发给我学习一下,不甚感激!!

可乐,加冰吗的主页 可乐,加冰吗 | 初学一级 | 园豆:102
提问于:2016-05-10 14:59
< >
分享
清除回答草稿
   您需要登录以后才能回答,未注册用户请先注册