第一步,导入文件
//ASI进行GET数据请求 需要导入的头文件是 ASIHTTPRequest.h
//ASI进行POST数据请求 需要导入的头文件是 ASIFormDataRequest.h
//都要遵守的协议是 ASIHTTPRequestDelegate
第二步,请求
<1>将字符串转成NSURL
NSURL * url = [NSURL URLWithString:PATH];
<2>封装请求对象
GET请求封装的请求对象是ASIHTTPRequest
POST请求封装的请求对象是ASIFormDataRequest
ASIFormDataRequest * request = [ASIFormDataRequest requestWithURL:url];
<3>设置代理
request.delegate =self;
<4>拼接接口
UITextField * tf = (UITextField *)[self.view viewWithTag:100];
[request addPostValue:tf.text forKey:@"chgmobile"];
<5>开始异步请求
[request startAsynchronous];
第三步,实现代理协议
-(void)requestFinished:(ASIHTTPRequest *) request
{
GDataXMLDocument * doc = [[GDataXMLDocument alloc]
initWithData:request.responseData options:0 error:nil];
NSArray * citys = [doc nodesForXPath:@"//city" error:nil];
GDataXMLElement * element = citys[0];
NSLog(@"%@",element.stringValue);
}