afnetworking源码解析怎样解析operation里面的头部信息

更多公众号:GCiOSDev我叫宫城,目前在有赞科技担任iOS开发,本帐号主要分享iOS开发文章以及疑难问题和我在阅读技术和非技术书籍的一些感悟最新文章对这篇文章不满意?您可以继续搜索:百度:搜狗:感谢您阅读iOS AFNetWorking源码详解(二)下,本文可能来自网络,如果侵犯了您的相关权益,请联系管理员。QQ:如何自定义标头添加到AFNetworking在JSONRequestOperation_百度知道
如何自定义标头添加到AFNetworking在JSONRequestOperation
提问者采纳
开机时IDE检测中不显示硬盘信息)这样进系统前就显示。2)IDE线质量不好或插得不牢: 1) 主板BIOS没电:换一条IDE线或将IDE线插在主板另一个IDE槽里,正确设置主&#47:&quot,重新进BIOS内检测硬盘。5)另外设置硬盘启动试试(是不是设置错误)、清一下灰也可以解决问题(有时是因为它引起的),分开两条IDE线连。 3)硬盘故障。6)还有一种情况;“reboot and select proper boot device or insert bootmedia in selected boot device and press a key” 硬盘检测失败的原因。 4)如果你的电脑每次都能检测到硬盘而不能进入系统的话,建议检修一下去,记不到硬盘信息。 解决办法你的电脑可能检测不到硬盘(检测不到硬盘的症状,如果你的系统日期不正确的话。 解决办法,连硬盘的线不要与其它IDE设备一起连接;从盘,内存重新插拔一下,可能需要更换,很可能是这个原因,把硬盘重新完全格式化,再重新装系统:更换BIOS电池,例如光驱。7)自己解决不了
来自团队:
为您推荐:
等待您来回答
下载知道APP
随时随地咨询
出门在外也不愁Object-C开发教程--如何在项目中使用AFNetworking
AFNetworking 是 iOS 一个使用很方便的网络开发框架。今天我们就简单介绍如何在我们的项目中使用它。
1、从官网最新的AFNetworking代码。
2、将AFNetWorking和UIKit+AFNetworking文件夹导入项目
3、添加类库 Security.framework、MobileCoreServices.framework、SystemConfiguration.framework
4、在使用的地方导入
#import AFNetworking.h
#import UIKit+AFNetworking.h
5、网络url访问测试。
NSString *URLTmp = @;
NSString *URLTmp1 = [URLTmp stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding];
//转码成UTF-8 否则可能会出现错误
URLTmp = URLTmp1;
NSURLRequest *request = [NSURLRequest requestWithURL:[NSURL URLWithString: URLTmp]];
AFHTTPRequestOperation *operation = [[AFHTTPRequestOperation alloc] initWithRequest:request];
[operation setCompletionBlockWithSuccess:^(AFHTTPRequestOperation *operation, id responseObject) {
NSLog(@Success: %@, operation.responseString);
NSString *requestTmp = [NSString stringWithString:operation.responseString];
NSData *resData = [[NSData alloc] initWithData:[requestTmp dataUsingEncoding:NSUTF8StringEncoding]];
//自带JSON解析
NSDictionary *resultDic = [NSJSONSerialization JSONObjectWithData:resData options:NSJSONReadingMutableLeaves error:nil];
NSLog(@success:%@,resultDic);
} failure:^(AFHTTPRequestOperation *operation, NSError *error) {
NSLog(@Failure: %@, error);
//[SVProgressHUD dismissWithError:@提交失败,请重试];
[operation start];
6、如何获取一张网络图片
NSString *url = @/uploads/allimg/__3.
UIImageView *imageView = [[UIImageView alloc] initWithFrame:CGRectMake(10.0f, 150.0f, 200.0f, 200.0f)];
[imageView setImageWithURL:[NSURL URLWithString:url]];
[self.view addSubview:imageView];
(window.slotbydup=window.slotbydup || []).push({
id: '2467140',
container: s,
size: '1000,90',
display: 'inlay-fix'
(window.slotbydup=window.slotbydup || []).push({
id: '2467141',
container: s,
size: '1000,90',
display: 'inlay-fix'
(window.slotbydup=window.slotbydup || []).push({
id: '2467143',
container: s,
size: '1000,90',
display: 'inlay-fix'
(window.slotbydup=window.slotbydup || []).push({
id: '2467148',
container: s,
size: '1000,90',
display: 'inlay-fix'坑货系列之-------用AFNetworking设置http请求头
最近在做的一个项目在获取网络数据的时候需要向服务器发送“Authorization”这个参数,而且这个参数是放在http请求的header里面的,所用的网络框架是开源的第三方框架AFNetworking。于是就翻了翻AFNetworking的api,发现有方法可以设置http header,如下:/** Sets the value for the HTTP headers set in request objects made by the HTTP client. If `nil`, removes the existing value for that header. @param field The HTTP header to set a default value for @param value The value set as default for the specified header, or `nil` */- (void)setValue:(NSString *)valueforHTTPHeaderField:(NSString *)这个方法在 AFHTTPRequestSerializer 类中申明,所以我就用了下面方法来请求网络:
AFHTTPRequestOperationManager *afManager = [AFHTTPRequestOperationManager manager];
[afManager.requestSerializer setValue:kTParamObject.authorization forHTTPHeaderField:@&Authorization&];
[afManager GET:urlStr parameters:nil success:^(AFHTTPRequestOperation *operation, id responseObject) {
} failure:^(AFHTTPRequestOperation *operation, NSError *error) {
}];我本以为会请求成功,结果却发现请求失败,错误信息中提示need login,我想肯定是参数没有传好,于是我就打开了Charles来抓自己的包,果然http header没有设置上,无语。。。于是,我就在网上搜,试了各种办法都没有用,最后只好用原始的NSMutableURLRequest来解决,代码如下:
NSMutableURLRequest *request = [NSMutableURLRequest requestWithURL:[NSURL URLWithString:urlStr]];
[request setHTTPMethod:@&GET&];
[request setValue:kTParamObject.authorization forHTTPHeaderField:@&Authorization&];
AFHTTPRequestOperation *operation = [[AFHTTPRequestOperation alloc] initWithRequest:request];
operation.responseSerializer = [AFJSONResponseSerializer serializer];
[operation setCompletionBlockWithSuccess:^(AFHTTPRequestOperation *operation, id responseObject) {
} failure:^(AFHTTPRequestOperation *operation, NSError *error) {
[operation start];看到数据出来了,终于松了一口气!!!
无相关信息
最新教程周点击榜
微信扫一扫AFNetworking&使用总结&(用法+JSON解析)
From:/?p=716
这几天在评论页面的时候发现get请求后加入2个以上的汉字会出现BadURL提示,断点调试发现是多中文字符惹的祸,所以在URL使用以前先转码成UTF-8即可
这里顺便说明下自己使用AFNetworking 的常用方法。
目前我只是用到
#import “AFHTTPClient.h”;
#import “AFHTTPRequestOperation.h”
发起一个请求
&NSString *URLTmp =
NSString *URLTmp1 = [URLTmp
stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding];
&//转码成UTF-8 &否则可能会出现错误
URLTmp = URLTmp1;
NSURLRequest *request = [NSURLRequest requestWithURL:[NSURL
URLWithString: URLTmp]];
AFHTTPRequestOperation *operation = [[AFHTTPRequestOperation alloc]
initWithRequest:request];
[operation setCompletionBlockWithSuccess:^(AFHTTPRequestOperation
*operation, id responseObject) {
NSLog(@"Success: %@", operation.responseString);
NSString *requestTmp = [NSString
stringWithString:operation.responseString];
NSData *resData = [[NSData alloc] initWithData:[requestTmp
dataUsingEncoding:NSUTF8StringEncoding]];
//系统自带JSON解析
NSDictionary *resultDic = [NSJSONSerialization
JSONObjectWithData:resData options:NSJSONReadingMutableLeaves
error:nil];
} failure:^(AFHTTPRequestOperation *operation, NSError *error)
NSLog(@”Failure: %@”, error);
[SVProgressHUD dismissWithError:@"提交失败,请重试"];
[operation start];
AFNetworking 下载图片
AFNETWorking 下载图片是异步并且可缓存到cache里面
非常好用不会阻塞主线程。用过的都说好!而且使用也简单!
#import “UIImageView+AFNetworking.h”
[imageView setImageWithURL:[NSURL URLWithString:URL]];
已投稿到:
以上网友发言只代表其个人观点,不代表新浪网的观点或立场。}

我要回帖

更多关于 afnetworking数据解析 的文章

更多推荐

版权声明:文章内容来源于网络,版权归原作者所有,如有侵权请点击这里与我们联系,我们将及时删除。

点击添加站长微信