这段时间,一直都在搞 webService 编程和 socket 编程,搞的死去活来的。总算是有点了解和认识,现在作笔录:<p>一,webService源代码</p> Nsstring *url = [Nsstring stringWithFormat:@"<?xml version=\"1.0\" encoding=\"utf-8\"?><soap:Envelope xmlns:xsi=\ "http://www.w3.org/2001/XMLSchema-instance\" xmlns:xsd=\"http://www.w3.org/2001/XMLSchema\" xmlns:soap=\"http://schemas.xmlsoap. org/soap/envelope/\"><soap:Body><%@ xmlns=\"http://www.zgbeidou.cn/\"><username>%@</username><password>%@</password> <servicepassword>YFGPS2008</servicepassword></%@></soap:Body></soap:Envelope>",type,nil,type]; Nsstring *urlLength = [Nsstring stringWithFormat:@"%d",[url length]]; [urlRequest addValue:@"text/xml; charset=utf-8" forHTTPHeaderField:@"Content-Type"]; [urlRequest addValue:urlLength forHTTPHeaderField:@"Content-Length"]; Nsstring *SOAPAction_str = [Nsstring stringWithFormat:@"http://www.zgbeidou.cn/%@",type]; [urlRequest addValue:SOAPAction_str forHTTPHeaderField:@"SOAPAction"]; [urlRequest setHTTPMethod:@"POST"]; [urlRequest setHTTPBody:[url dataUsingEncoding:NSUTF8StringEncoding]]; //请求并接收返回的数据 NSURLResponse *reponse; NSError *error = nil; NSData *responseData = [NSURLConnection sendSynchronousRequest:urlRequest returningResponse:&reponse error:&error]; NSMutableString *resultString = [[NSMutableString alloc]initWithData:responseData encoding:NSUTF8StringEncoding]; // NSLog(@"urlRequest = %@",resultString); //解析xml数据 GdataxMLDocument *doc = [[GdataxMLDocument alloc]initWithData:responseData options:0 error:nil]; GdataxMLElement *rootElement = [doc rootElement]; NSData *data = [[rootElement stringValue]dataUsingEncoding:NSUTF8StringEncoding]; NSArray *arr = [NSJSONSerialization JSONObjectWithData:data options:NSJSONReadingallowFragments error:nil]; NSLog(@"arr11111 = %@",arr );
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 [email protected] 举报,一经查实,本站将立刻删除。