標籤:http io os ar for 資料 art sp log
asihttprequest 為第三方資料請求,一下為get 和post 兩種請求。
Get:
NSString *[email protected]"Tony";
NSString *[email protected]"123";
NSString *postURL=[NSString stringWithFormat:@"http://192.168.2.2:1234/WebServiceDemo.asmx/LoginIn?loginName=%@&pwd=%@",loginName,pwd];
NSLog(@"發送時請求URL%@",postURL);
ASIHTTPRequest *request=[[ASIHTTPRequest alloc] initWithURL:[NSURL URLWithString:postURL]];
[request setRequestMethod:@"GET"];
[request startSynchronous];
NSError *error=[request error];
if(!error)
{
NSString *result=[request responseString];
NSLog(result);
}
Post :
//---------------Http Post-----------------------
NSString *postUrl=[NSString stringWithFormat:@"http://192.168.2.2:1234/WebServiceDemo.asmx/GetInfo"];
ASIFormDataRequest *request=[[ASIFormDataRequest alloc] initWithURL:[NSURL URLWithString:postUrl]];
// 設定 post參數
[request setPostValue:@"1233" forKey:@"LoginName"];
[request setPostValue:@"dsadasdasd" forKey:@"pwd"];
[request startSynchronous];
NSString *result=[request responseString];
NSLog(result);
[result release];
IOS http 請求