ios http都设置哪些header
2016-07-07 · 百度知道合伙人官方认证企业
兄弟连教育
兄弟连教育成立于2006年,11年来专注IT职业教育,是国内专业的IT技术培训学校。2016年成功挂牌新三板(股票代码:839467)市值过亿。开设专注程序员培训专注php、Java、UI、云计算、Python、HTML5、
向TA提问
关注
展开全部
1、让类实现这两个接口:
NSURLConnectionDelegate,NSURLConnectionDataDelegate
2、实现接口对应的方法:
-(void)connection:(NSURLConnection *)connection didReceiveResponse:(NSURLResponse *)response{
NSInteger code=[(NSHTTPURLResponse*)response statusCode];
NSLog(@"didReceiveResponse....code=%d",code);
}
-(void)connection:(NSURLConnection *)connection didFailWithError:(NSError *)error{
NSLog(@"didFailWithError...%@",[error description]);
}
-(void)connectionDidFinishLoading:(NSURLConnection *)connection{
NSLog(@"connectionDidFinishLoading....");
}
-(void)connection:(NSURLConnection *)connection didReceiveData:(NSData *)data{
NSString *str=[[NSString alloc]initWithData:data encoding:NSASCIIStringEncoding];
NSLog(@"didReceiveData....data=%@",str);
}
3、设置NSMutableURLRequest和发起请求:
NSString *strUrl=[NSString stringWithFormat:@" 你的地址"];
NSURL *url=[NSURL URLWithString:strUrl];
NSMutableURLRequest *request=[[NSMutableURLRequest alloc]initWithURL:url cachePolicy:NSURLRequestReloadIgnoringCacheData timeoutInterval:20];
[request setHTTPMethod:@"GET"];
[request setValue:@"application/x-www-form-urlencoded" forHTTPHeaderField:@"Content-Type"];
[request setValue:@"字段对应的值1" forHTTPHeaderField:@"你头部的字段1"];
[request setValue:@"字段对应的值2" forHTTPHeaderField:@"你头部的字段2"];
mConn=[[NSURLConnection alloc]initWithRequest:request delegate:self startImmediately:true];
[mConn start];
NSURLConnectionDelegate,NSURLConnectionDataDelegate
2、实现接口对应的方法:
-(void)connection:(NSURLConnection *)connection didReceiveResponse:(NSURLResponse *)response{
NSInteger code=[(NSHTTPURLResponse*)response statusCode];
NSLog(@"didReceiveResponse....code=%d",code);
}
-(void)connection:(NSURLConnection *)connection didFailWithError:(NSError *)error{
NSLog(@"didFailWithError...%@",[error description]);
}
-(void)connectionDidFinishLoading:(NSURLConnection *)connection{
NSLog(@"connectionDidFinishLoading....");
}
-(void)connection:(NSURLConnection *)connection didReceiveData:(NSData *)data{
NSString *str=[[NSString alloc]initWithData:data encoding:NSASCIIStringEncoding];
NSLog(@"didReceiveData....data=%@",str);
}
3、设置NSMutableURLRequest和发起请求:
NSString *strUrl=[NSString stringWithFormat:@" 你的地址"];
NSURL *url=[NSURL URLWithString:strUrl];
NSMutableURLRequest *request=[[NSMutableURLRequest alloc]initWithURL:url cachePolicy:NSURLRequestReloadIgnoringCacheData timeoutInterval:20];
[request setHTTPMethod:@"GET"];
[request setValue:@"application/x-www-form-urlencoded" forHTTPHeaderField:@"Content-Type"];
[request setValue:@"字段对应的值1" forHTTPHeaderField:@"你头部的字段1"];
[request setValue:@"字段对应的值2" forHTTPHeaderField:@"你头部的字段2"];
mConn=[[NSURLConnection alloc]initWithRequest:request delegate:self startImmediately:true];
[mConn start];
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
Storm代理
2023-07-25 广告
2023-07-25 广告
StormProxies是一家可靠的代理服务提供商,提供原生IP(住宅原生IP)和高匿名代理服务。以下是关于StormProxies的原生IP服务的一些信息:1. 住宅原生IP:StormProxies提供的住宅原生IP是指从真实的家庭或企...
点击进入详情页
本回答由Storm代理提供
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询