2012-05-17 34 views

回答

0

您可以使用ASIHTTPRequest,你可以這樣說:

ASIFormDataRequest *request = [ASIFormDataRequest requestWithURL:someUrl]; 
[request setRequestMethod:@"POST"]; 
[request setPostValue:@"..." forKey:@"user"]; 
[request setPostValue:@"..." forKey:@"password"]; 
[request setDelegate:self]; 
[request startAsyncrhonous]; 

有委託方法對於像請求請求完成或失敗,因爲

- (void)requestFinished:(ASIHTTPRequest *)request 
{ 
    NSLog(@"Response %d ==> %@", request.responseStatusCode, [request responseString]); 
} 

- (void)requestFailed:(ASIHTTPRequest *)request 
{ 
    NSLog(@"Response %d ==> %@", request.responseStatusCode, [request responseString]); 
} 

您可以隨時下載ASIHTTPRequest並能任何進一步的幫助,請訪問documentation

希望這會有所幫助!

0
NSURL *url = [NSURL URLWithString:@"http://xyz"]; 

NSMutableURLRequest *request = [NSMutableURLRequest requestWithURL:url 
                 cachePolicy:NSURLRequestUseProtocolCachePolicy timeoutInterval:30.0]; 

NSString *req; 


    req = [NSString stringWithFormat:@"Name=%@&Password=%@",userName,pass];// userName and pass are string 

[request setHTTPMethod:@"POST"]; 
[request setHTTPBody: [req dataUsingEncoding:NSISOLatin1StringEncoding]]; 
NSURLConnection *connection = [[NSURLConnection alloc]initWithRequest:request delegate:self]; 
[connection start]; 

下面是一個委託,它將帶來數據

-(void)connection:(NSURLConnection*)connection didReceiveData:(NSData *)data 
{ 
NSError *erro; 
NSDictionary *jsonData = [NSJSONSerialization JSONObjectWithData:data options:kNilOptions error:&erro]; 

NSLog(@"your data in dictionary is = %@",jsonData); 

} 

希望這將幫助你!

相關問題