NSHTTPURLResponse *response = nil;
NSError *error = nil;
[NSURLConnection sendSynchronousRequest:webView.request returningResponse:&response error:&error];
NSLog(@"%@",webView.request);
int errorCode = (int)[error code];
NSLog( @"Error Code: %i", errorCode );
int statusCode = (int)[response statusCode];
NSLog( @"Status Code: %i", statusCode );
if ( [response respondsToSelector:@selector(allHeaderFields)] ) {
NSDictionary *dictionary = [response allHeaderFields];
NSLog( @"%@", [dictionary description] );
}
同样可以根据request创建连接得到response
NSData *postData = [pair dataUsingEncoding:NSUTF8StringEncoding allowLossyConversion:YES];
NSMutableURLRequest *request = [[NSMutableURLRequest alloc] init];
[request setURL:[NSURL URLWithString: [[NSString alloc] initWithFormat:@"%@", ACTION_URL]]];
[<span style="font-family: Arial, Helvetica, sans-serif;">request</span><span style="font-family: Arial, Helvetica, sans-serif;"> setHTTPMethod: @"POST"];</span>
[request setValue: HOST forHTTPHeaderField:@"Referer"];
[request setHTTPBody: postData];
pair是参数串
ACTION_URL是提交url
HOST是referer主机名
可以添加其他参数通过 setValue,比如UserAgent等。