ios菜鸟之路:iphone连接webservice服务操作
来源:互联网 发布:kindle保护套推荐知乎 编辑:程序博客网 时间:2024/06/05 21:12
iphone连接webservice的操作:
- (IBAction)connectwebservice:(id)sender {
NSString *username=@"s";
NSString *pwd=@"123456";
NSString *soapMessage1 = [NSString stringWithFormat:
@"<?xml version=\"1.0\" encoding=\"utf-8\"?>\n"
"<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/\">\n"
"<soap:Body>\n"
"<login xmlns=\"http://mspackage\">\n" //login是要执行的操作方法,xmlns的值是 命名空间。
"<i>1</i>\n" //后边是三个参数 i值 username值和pwd值
"<username>%@</username>\n"
"<pwd>%@</pwd>\n"
"</login>\n"
"</soap:Body>\n"
"</soap:Envelope>\n",username, pwd];
//请求发送到的路径
//http://192.168.0.231:8080/axis2/services/mobileservice 是 服务地址
NSURL * url = [NSURL URLWithString:[@"http://192.168.0.231:8080/axis2/services/mobileservice" /stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding]];
NSMutableURLRequest *theRequest = [NSMutableURLRequest requestWithURL:url];
NSString *msgLength = [NSString stringWithFormat:@"%d", [soapMessage1 length]];
//以下对请求信息添加属性前四句是必有的,第五句是soap信息。
[theRequest addValue: @"text/xml; charset=utf-8"forHTTPHeaderField:@"Content-Type"];
[theRequest addValue: @"http://mspackage/login"forHTTPHeaderField:@"soapAction"];
[theRequest addValue: msgLength forHTTPHeaderField:@"Content-Length"];
[theRequest setHTTPMethod:@"POST"];
[theRequest setHTTPBody: [soapMessage1 dataUsingEncoding:NSUTF8StringEncoding]];
NSURLResponse *reponse;
NSError *error = nil;
//put数据之后的返回信息
UIAlertView *alert = nil;
if(error)
{
alert = [[UIAlertView alloc]
initWithTitle:@"提示"
message:[error description]
delegate:self
cancelButtonTitle:nil
otherButtonTitles:@"OK", nil];
}else
{
if(responseData)
{
NSString *responseString = [[NSString alloc] initWithData:responseData encoding:NSUTF8StringEncoding];
NSRange range = [responseString rangeOfString:@"username"];
if (range.length)
{
alert = [[UIAlertView alloc]
initWithTitle:@"登陆成功!"
message:[responseString description]
delegate:self
cancelButtonTitle:nil
otherButtonTitles:@"OK", nil];
}else
{
alert = [[UIAlertView alloc]
initWithTitle:@"用户名密码错误!"
message:[responseData description]
delegate:self
cancelButtonTitle:nil
otherButtonTitles:@"OK", nil];
}
}
}
[alert show];
}
- ios菜鸟之路:iphone连接webservice服务操作
- ios菜鸟之路:iphone google map 定位的实现
- iOS菜鸟之路
- ios菜鸟之路:iphone开发中UIAlertView开发,及多按键的实现
- ios菜鸟之路:iphone使用照片管理器,从本地上传或摄像头拍照
- IOS菜鸟起飞之路
- IOS菜鸟学习之路
- iOS 连接webservice(1)
- iphone ios 延时操作
- iphone ios 数据库操作
- iOS菜鸟笔记3:Hello,iPhone!
- ios菜鸟之路:标题栏UINavigationcontroller开发
- 菜鸟菜鸟菜鸟菜鸟编程之路
- ios学习笔记之三- iPhone模拟器基本操作
- Asp.Net编写Web服务(WebService)与SQL2005连接操作
- iOS开发之iPhone通过get和post方式请求asp.net webservice
- 菜鸟学习之webservice 测试工具 soapUI
- 菜鸟之webservice(一) 服务端搭建
- 敏捷开发一千零一问系列之十四:敏捷开发加班吗?
- 关于flash跨域数据加载
- 创建一个基于ASP.NET 2.0的JSON WebService
- smtp相关
- 敏捷开发一千零一问系列之十五:同时实施CMMI和敏捷哪个为主?
- ios菜鸟之路:iphone连接webservice服务操作
- Flash Mp3播放器中写的Lrc歌词解析函数
- IT学生在校学习六层楼
- 博弈论专题1 HDOJ 1846 Brave Game
- linux下修改tomcat的默认目录
- 敏捷开发一千零一问系列之十六:如何让开发人员学习产品?
- 流处理器数量
- protected与default的区别
- 敏捷开发一千零一问系列之十七:长期受制于强势客户怎么办?(上)