iOS开发之了解iPhone中Get和Post方式

移动开发 iOS
本文主要是通过iPhone中Get和Post方式去请求asp.net webservice的一个实例,让我们来学习GET和POST方式的用法,先来看详细内容。

iOS开发之了解iPhoneGetPost方式是本文要介绍的内容,本篇文章通过一个简单的例子来展现iPhone通过getpost方式请求asp.net webservice。

webservice

1、创建一个webservice,如图:

iOS开发之了解iPhone中Get和Post方式

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

  1. <webServices> 
  2.     <protocols> 
  3.         <add name="HttpSoap"/> 
  4.         <add name="HttpPost"/> 
  5.         <add name="HttpGet"/> 
  6.         <add name="Documentation"/> 
  7.     </protocols> 
  8. </webServices> 

iphone客户端调用:

1、get的方式:

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

2、post的方式:

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

小结:iOS开发之了解iPhoneGetPost方式的内容介绍完了,希望本文对你有所帮助!

责任编辑:zhaolei 来源: 博客园
相关推荐

2009-09-28 13:23:54

HTTP编程

2011-08-04 17:19:49

iPhone开发 Xcode 文档

2013-07-23 07:34:54

iOS开发学习适配iphone5

2011-06-08 11:02:14

GetPost

2011-08-01 18:44:16

iPhone开发 UIALertVie UIActionSh

2011-08-22 15:15:49

iPhone开发NSMutableAr排序

2009-07-29 16:53:52

ASP.NET Get

2011-08-08 10:23:41

iPhone 流播放 文件

2011-06-08 11:05:38

getpost

2023-08-07 09:25:06

GETPOSTHTTP请求

2011-07-08 14:58:16

iPhone Xcode iOS

2014-07-24 10:00:21

2011-08-12 13:30:27

iPhoneASIFormData架构

2018-01-16 15:06:36

iPhone XiOS

2013-07-22 16:10:35

iOS游戏设计营销

2011-08-01 18:27:58

iPhone开发 UISearchBa

2011-08-10 10:10:21

iPhoneUIPopoverCo

2015-08-06 13:33:22

PHPGETPOST

2022-08-03 07:04:56

GETHTTPPOST

2015-10-27 11:06:51

PHPGETPOST
点赞
收藏

51CTO技术栈公众号