栏目分类:
子分类:
返回
名师互学网用户登录
快速导航关闭
当前搜索
当前分类
子分类
实用工具
热门搜索
名师互学网 > IT > 软件开发 > 后端开发 > C/C++/C#

iPhone请求asp.net webservice

C/C++/C# 更新时间: 发布时间: IT归档 最新发布 模块sitemap 名妆网 法律咨询 聚返吧 英语巴士网 伯小乐 网商动力

iPhone请求asp.net webservice

这篇文章,我将通过一个简单的例子来展现iPhone通过get和post方式请求asp.net webservice。

webservice

1、创建一个webservice

2、在webconfig中启用http get 和http post。

        
            
                
                
                
                
            

        

iphone客户端调用:

1、get的方式:

NSString *queryString =
          [NSString stringWithFormat:
    @“http://10.5.23.117:5111/Service1.asmx/HelloWorld?param=123%@“,
    ipAddress.text];
    NSURL *url = [NSURL URLWithString:queryString];
    NSMutableURLRequest *req = [NSMutableURLRequest requestWithURL:url];
    [req addValue:@“text/xml; charset=utf-8” forHTTPHeaderField:@“Content-Type”];
    [req addValue:0 forHTTPHeaderField:@“Content-Length”];
    [req setHTTPMethod:@“GET”];
    [activityIndicator startAnimating];
    conn = [[NSURLConnection alloc] initWithRequest:req delegate:self];
    if (conn) {
        webData = [[NSMutableData data] retain];
    }

2、post的方式:

?

NSString *postString =@"123";    NSURL *url = [NSURL URLWithString:        @“http://10.5.23.117:5111/Service1.asmx/HelloWorld2”];    NSMutableURLRequest *req = [NSMutableURLRequest requestWithURL:url];    NSString *msgLength = [NSString stringWithFormat:@“%d”, [postString length]];    [req addValue:@“application/x-www-form-urlencoded”        forHTTPHeaderField:@“Content-Type”];    [req addValue:msgLength forHTTPHeaderField:@“Content-Length”];    [req setHTTPMethod:@“POST”];    [req setHTTPBody: [postString dataUsingEncoding:NSUTF8StringEncoding]];    [activityIndicator startAnimating];    conn = [[NSURLConnection alloc] initWithRequest:req delegate:self];    if (conn) {        webData = [[NSMutableData data] retain];    }


转载请注明:文章转载自 www.mshxw.com
本文地址:https://www.mshxw.com/it/231887.html
我们一直用心在做
关于我们 文章归档 网站地图 联系我们

版权所有 (c)2021-2022 MSHXW.COM

ICP备案号:晋ICP备2021003244-6号