kangzubin / xmnetworking Goto Github PK
View Code? Open in Web Editor NEWA lightweight but powerful network library with simplified and expressive syntax based on AFNetworking.
License: MIT License
A lightweight but powerful network library with simplified and expressive syntax based on AFNetworking.
License: MIT License
如题?
默认不支持content-type: text/html或者text/plain,能在配置里改吗?还是只能修改源文件?
(https://github.com/kangzubin/XMNetworking/blob/master/XMNetworking/Core/XMRequest.m#L234)
这里应该修改为:
XM_SAFE_BLOCK(_chainFinishedBlock, _responseArray, nil);
https://github.com/kangzubin/XMNetworking/blob/master/XMNetworking/Core/XMCenter.m#L295
这里应该是
[chainRequest onFinishedOneRequest:request response:responseObject error:error];
吧?
https://github.com/kangzubin/XMNetworking/blob/master/XMNetworking/Core/XMRequest.m#L219
并且这里暂时也没有用到request
入参.
运行 Demo程序, 首次进入程序时滑动很流畅,60FPS 基本不会掉帧
但是放置一分钟,再次滑动,掉帧严重,会到40FPS 左右,不知道为什么?
要访问的地址是http://127.0.0.1:5000/api/user/xxx/signin,
经测试,这样设置不能成功访问,
config.generalServer = @"http://127.0.0.1:5000/api";
request.api = @"/user/xxx/signin"
必须要这样设置
config.generalServer = @"http://127.0.0.1:5000/api/";
request.api = @"user/xxx/signin"
建议兼容多种/
的写法?
你好,请求成功后,需要获取allHeaderFields信息,要怎么做?
链式请求 sendChainRequest 的时候不走 setRequestProcessBlock 方法?
pod search XMNetworking pods版本为1.2.0.beta.1
其他第三方要求pod af ,会不会导致冲突
我这边传给服务器的参数是以raw的方式传给服务器,parameters这个参数不起作用了,请问该怎么处理
怎样实时的监听网络状态
NSArray *names = @[@"headFile",@"idCardFrontFile",@"idCardBackFile",@"qualificationCertificateFile "];
NSArray *fileNames = @[@"head.jpg",@"idCardFront.jpg",@"idCardBack.jpg",@"award.jpg"];
NSArray *fileDatas = @[headerData,idCardFrontData,idCardBackData,awardData];
request.headers = @{@"Content-Type":@"multipart/form-data"};
request.url = [NSString uuidRequestPathWithPath:@"http://192.168.10.182:8080/escst_interface/person/addPerson"];
request.timeoutInterval = 8.f;
request.requestType = kXMRequestUpload;
request.parameters = param;
// XMUploadFormData *headerForm = [XMUploadFormData formDataWithName:@"headFile" fileName:@"avatar" mimeType:@"image/jpg" fileData:headerData];
for (int i = 0; i < 4; i++) {
[request addFormDataWithName:names[i] fileName:fileNames[i] mimeType:@"image/jgg" fileData:fileDatas[i]];
}
这个是在RequestBlock中写的,有什么问题
一直想自己封装个网络库,不过老是给自己的懒惰找理由。今天看到xm,所有的方法都看了一遍,我想做的,xm全做了。如果能再加上缓存,估计我可以把自己的项目全部都换血用xm了
我这边集成海康SDK时,他们的登录静态库使用了afn2.5.3,改不了源码,很是纠结,我尝试去改XM框架,发现问题好多,要改的不只是XMEngine里面的东西,而且,我也没认真研究afn的迁移改动,想问问您,有没有基于老版本的框架,没有的话,能不能给些修改指导意见。万分感谢!!!
[self loadData1];
[self loadData2];
[self loadData3];
连续请求三次请求的时候,主线程返回数据
wow,jianjie,jincou,lihaile~
如果能添加这个功能的支持就太好了
当网络断开后,我取消掉所有网络请求,并把对应的identifier保存到一个数组中去,以便重新联网后再次请求数据,可问题是我如何恢复这个请求呢?
[XMCenter setErrorProcessBlock:^(XMRequest *request, NSError * _Nullable __autoreleasing *error) {
// 比如对不同的错误码统一错误提示等
}];
这个block的error为啥点不出来code
直接用afn3.0 代码如下:
AFURLSessionManager *manager = [[AFURLSessionManager alloc] initWithSessionConfiguration:[NSURLSessionConfiguration defaultSessionConfiguration]];
[[manager dataTaskWithRequest:request completionHandler:^(NSURLResponse * _Nonnull response, id _Nullable responseObject, NSError * _Nullable error) {
if (!error) {
} else {
NSLog(@"Error: %@, %@, %@", error, response, responseObject);
}
}] resume];
真机
6s
iOS10.1
当在didFinishLaunchingWithOptions中调用api时会直接判断网络未连接
NSLocalizedDescription=Request failed: unacceptable content-type: application/rss+xml
How can I receive data of content-type: application/rss+xml???
XMRequest *request = [XMRequest request];
XM_SAFE_BLOCK(configBlock, request);
经过XM_SAFE_BLOCK处理以后,request以前设置的参数被清除。
成功回调发生在哪个线程?tableViewCell通过自动布局自动行高,数据请求成功回调reloaddata后....crash,将reloadData手动放到主线程...妥妥的好了。
request.headers = @{@"Content-Type":@"multipart/form-data"};
request.url = [NSString uuidRequestPathWithPath:@"http://192.168.10.182:8080/escst_interface/person/"];
request.timeoutInterval = 8.f;
request.requestType = kXMRequestUpload;
request.parameters = param;
// XMUploadFormData *headerForm = [XMUploadFormData formDataWithName:@"headFile" fileName:@"avatar" mimeType:@"image/jpg" fileData:headerData];
for (int i = 0; i < 4; i++) {
[request addFormDataWithName:names[i] fileName:fileNames[i] mimeType:@"image/jgg" fileData:fileDatas[i]];
}
这样写有什么问题吗
Error Domain=com.alamofire.error.serialization.response Code=-1016 "Request failed: unacceptable content-type: application/atom+xml" UserInfo={com.alamofire.serialization.response.error.response=<NSHTTPURLResponse: 0x6080002305c0> { URL: http://101.201.81.96:8081/biz-ws-deploy/service/play/play/findPlayHomePage?userId=e549d1e054096f4701540992b516001b } { status code: 200, headers {
"Content-Type" = "application/atom+xml";
Date = "Fri, 06 Jan 2017 07:32:00 GMT";
Server = "Apache-Coyote/1.1";
"Transfer-Encoding" = Identity;
} }, NSErrorFailingURLKey=http://101.201.81.96:8081/biz-ws-deploy/service/play/play/findPlayHomePage?userId=e549d1e054096f4701540992b516001b, com.alamofire.serialization.response.error.data=<7b226461 7461223a 7b224c69 66654c69 7374223a 5b7b2263 6c617373 69667922 3a223022 2c22636f 6d6d6f64 69747949 64223a22 65353439 64316530 35366439 36303430 30313536 66393665 35323638 30383538 222c2263 6f6d6d6f 64697479 4e616d65 223a22e8 a281e8ae b0e4b8b2 e4b8b2e9 a699efbc 8834e4ba bae5b9b2 e99485e5 a597e9a4 90efbc89 222c2269 6d67223a 22687474 703a2f2f 3130312e 3230312e 38312e39 363a3830 .......
我使用charles 抓取我发起的请求, 耗时一般最多都是100多200多毫秒, 但是走到 finished 回调的时候, 打印花费时间 长达 3s, 而且有时是正常的, 一直在1s, 2s, 3s 徘徊, 请问可能是什么原因造成的?
目前有第三方pod依赖AFNetworking,再引入XMNetworking就失败了。
本以为上传文件跟普通请求差别不大,没想到请求方式在实现文件里被写死了 😓
请求 request 设置如下 :
request.requestType = kXMRequestUpload; request.httpMethod = kXMHTTPMethodPATCH; [request addFormDataWithName:@"file" fileName:@"user_avatar.jpg" mimeType:@"image/jpeg" fileData:editData];
结果直接报错了。后来发现是这段代码的问题
`- (void)xm_uploadTaskWithRequest:(XMRequest *)request
completionHandler:(XMCompletionHandler)completionHandler {
AFURLSessionManager *sessionManager = [self xm_getSessionManager:request];
AFHTTPRequestSerializer *requestSerializer = [self xm_getRequestSerializer:request];
__block NSError *serializationError = nil;
NSMutableURLRequest *urlRequest = [requestSerializer multipartFormRequestWithMethod:@"POST"
URLString:request.url
parameters:request.parameters
constructingBodyWithBlock:^(id<AFMultipartFormData> formData) {`
请问这该如何是好呀。什么时候可以修复一下这个问题呢?
sendChainRequest 等实例方法没有冒号对齐
如题
#pragma mark - Accessor
- (AFHTTPSessionManager *)sessionManager {
if (!_sessionManager) {
_sessionManager = [AFHTTPSessionManager manager];
_sessionManager.requestSerializer = self.afHTTPRequestSerializer;
_sessionManager.responseSerializer = self.afHTTPResponseSerializer;
_sessionManager.operationQueue.maxConcurrentOperationCount = 5; // this is incorrect
_sessionManager.completionQueue = xm_request_completion_callback_queue();
}
return _sessionManager;
}
We should not modify this property maxConcurrentOperationCount
see : https://github.com/AFNetworking/AFNetworking/issues/3720 for detail
Hi, I added crt file into bundles and used this code
NSString *certPath = [[NSBundle bundleForClass:[self class]] pathForResource:@"PushCrt" ofType:@"crt"];
NSData *certData = [NSData dataWithContentsOfFile:certPath];
[XMCenter addSSLPinningCert:certData];
[XMCenter addSSLPinningURL:@"https://*****.net"];
[XMCenter sendRequest:^(XMRequest *request) {
request.url = [NSString stringWithFormat:@"https://*****:8801/api/v2/tokens"];
request.parameters = @{@"device": @"ios", @"token" : @"aa", @"channel" : @"default"};
request.httpMethod = kXMHTTPMethodPOST;
request.headers = @{@"X-AN-APP-NAME" : @"**", @"X-AN-APP-KEY" : @"**"};
//request.responseSerializerType = kXMResponseSerializerJSON;
} onSuccess:^(id responseObject) {
NSLog(@"%@",responseObject);
} onFailure:^(NSError *error) {
NSLog(@"%@",error);
NSLog(@"%@",[error localizedFailureReason]);
} onFinished:^(id responseObject, NSError *error) {
}];
but it exception by below error, any hint?
Error Domain=NSURLErrorDomain Code=-999 "cancelled" UserInfo={NSErrorFailingURLKey=https://*:8801/api/v2/tokens, NSLocalizedDescription=cancelled, NSErrorFailingURLStringKey=https://:8801/api/v2/tokens}
与BatchRequest不同,我的理解是,链式调用其实就是同步多个XMRequest的发起和返回,在我们的项目中,我是使用dispatch_group 来做同步的,最终实现的ChainRequest调用方式和您这个BatchRequest 一样的,也是传入一组requestArray,利用requestArray 实现一个Queue的数据结构,所以能够保证request的发起顺序,并同步responseObject在responseArray的位置。而在您的项目中XMChainRequest的实现方式其实和我的方式差不多吧,不过您是使用dispatch_semaphore_t 配合游标_chainIndex来做同步。哈哈哈,突然有个想法,dispatch_group工作原理就是这么干的?
�回到正题,两种方式哪个新能更好?健壮性更高?出于本能吧,看到 [_responseArray addObject:[NSNull null]]; 以及[_responseArray replaceObjectAtIndex:index withObject:responseObject]; 心里就会停顿,总是会担心Crash。
how i can set acceptableContentTypes .when the response data is not json?
error info:
Error Domain=com.alamofire.error.serialization.response Code=-1016 "Request failed: unacceptable content-type: text/html" UserInfo={NSLocalizedDescription=Request failed: unacceptable content-type: text/html, NSErrorFailingURLKey=
你们的to do list里面有提到request cache 那么想问下 什么时候才能支持?
请问框架支持网络缓存吗 缓存post put。我看项目里似乎没有支持缓存
response数据是text/html格式,还要去AFN的AFHTTPResponseSerializer中改acceptableContentTypes,在XMN的XMEngine修改- (AFHTTPSessionManager *)sessionManager中的_sessionManager.responseSerializer.acceptableContentTypes
却无效,这是什么原因?
怀着无比激动的心情感谢作者,这就是我一直想要的!太谢谢了! 希望能够一直维护下去!
想了解一下XM_SAFE_BLOCK
这个宏是实现什么功能的?还有为什么能实现
不知道是为什么
https://github.com/kangzubin/XMNetworking/blob/master/XMNetworking/Core/XMEngine.m#L381
这里放宽了对于 Content-Type 的限制,不知意义何在?如果仅仅是为了好用的话,感觉是没有必要的。
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.