自拍偷在线精品自拍偷,亚洲欧美中文日韩v在线观看不卡

iOS開發(fā)之了解iPhone中Get和Post方式

移動開發(fā) iOS
本文主要是通過iPhone中Get和Post方式去請求asp.net webservice的一個實例,讓我們來學習GET和POST方式的用法,先來看詳細內容。

iOS開發(fā)之了解iPhoneGetPost方式是本文要介紹的內容,本篇文章通過一個簡單的例子來展現(xiàn)iPhone通過getpost方式請求asp.net webservice。

webservice

1、創(chuàng)建一個webservice,如圖:

iOS開發(fā)之了解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開發(fā)之了解iPhoneGetPost方式的內容介紹完了,希望本文對你有所幫助!

責任編輯:zhaolei 來源: 博客園
相關推薦

2009-09-28 13:23:54

HTTP編程

2011-08-04 17:19:49

iPhone開發(fā) Xcode 文檔

2013-07-23 07:34:54

iOS開發(fā)學習適配iphone5

2011-08-01 18:44:16

iPhone開發(fā) UIALertVie UIActionSh

2011-06-08 11:02:14

GetPost

2011-08-22 15:15:49

iPhone開發(fā)NSMutableAr排序

2009-07-29 16:53:52

ASP.NET Get

2011-08-08 10:23:41

iPhone 流播放 文件

2011-07-08 14:58:16

iPhone Xcode iOS

2011-06-08 11:05:38

getpost

2023-08-07 09:25:06

GETPOSTHTTP請求

2011-08-01 18:27:58

iPhone開發(fā) UISearchBa

2011-08-10 10:10:21

iPhoneUIPopoverCo

2011-08-12 13:30:27

iPhoneASIFormData架構

2014-07-24 10:00:21

2018-01-16 15:06:36

iPhone XiOS

2013-07-22 16:10:35

iOS游戲設計營銷

2011-07-08 17:45:19

iPhone 文檔

2013-07-29 05:01:31

iOS開發(fā)iOS開發(fā)學習按鈕拖動和點擊

2011-07-29 15:47:21

iPhone開發(fā) Objective- C
點贊
收藏

51CTO技術棧公眾號