AFNetworking怎么设置网络超时的时间
2017-11-07
展开全部
有时,网络速度非常慢,为了节省资源,用户可以自己设置需要的网络超时时间。
打开注册表编辑器,单击窗口左侧的树形列表,依次HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows NT\CurrentVersion\Winlogon子键,在其键值窗口中新建一个“DWORD值”类型的键值项,将其命名为“SlowLinkTimeOut”,设置键值为“3000”(单位是毫秒),重新启动电脑后,设置生效。
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
2017-11-07
展开全部
POST请求
+ (AFHTTPRequestOperation *)GETMethod:(NSString *)URLString
parameters:(id)parameters
success:(void (^)(AFHTTPRequestOperation *operation, id responseObject))success
failure:(void (^)(AFHTTPRequestOperation *operation, NSError *error))failure {
AFHTTPRequestOperationManager *manager = [AFHTTPRequestOperationManager manager];
// 设置超时时间
[manager.requestSerializer willChangeValueForKey:@"timeoutInterval"];
manager.requestSerializer.timeoutInterval = 10.f;
[manager.requestSerializer didChangeValueForKey:@"timeoutInterval"];
AFHTTPRequestOperation *httpOperation = [manager GET:URLString
parameters:parameters
success:^(AFHTTPRequestOperation *operation, id responseObject) {
if (success) {
success(operation, responseObject);
}
}
failure:^(AFHTTPRequestOperation *operation, NSError *error) {
if (failure) {
failure(operation, error);
}
}];
return httpOperation;
}
GET请求
+ (AFHTTPRequestOperation *)POSTMethod:(NSString *)URLString
parameters:(id)parameters
success:(void (^)(AFHTTPRequestOperation *operation, id responseObject))success
failure:(void (^)(AFHTTPRequestOperation *operation, NSError *error))failure {
AFHTTPRequestOperationManager *manager = [AFHTTPRequestOperationManager manager];
manager.requestSerializer = [AFJSONRequestSerializer serializer];
manager.responseSerializer.acceptableContentTypes = [manager.responseSerializer.acceptableContentTypes setByAddingObject:@"text/html"];
// 设置超时时间
[manager.requestSerializer willChangeValueForKey:@"timeoutInterval"];
manager.requestSerializer.timeoutInterval = 10.f;
[manager.requestSerializer didChangeValueForKey:@"timeoutInterval"];
AFHTTPRequestOperation *httpOperation = [manager POST:URLString
parameters:parameters
success:^(AFHTTPRequestOperation *operation, id responseObject) {
if (success) {
success(operation, responseObject);
}
}
failure:^(AFHTTPRequestOperation *operation, NSError *error) {
if (failure) {
failure(operation, error);
}
}];
return httpOperation;
}
+ (AFHTTPRequestOperation *)GETMethod:(NSString *)URLString
parameters:(id)parameters
success:(void (^)(AFHTTPRequestOperation *operation, id responseObject))success
failure:(void (^)(AFHTTPRequestOperation *operation, NSError *error))failure {
AFHTTPRequestOperationManager *manager = [AFHTTPRequestOperationManager manager];
// 设置超时时间
[manager.requestSerializer willChangeValueForKey:@"timeoutInterval"];
manager.requestSerializer.timeoutInterval = 10.f;
[manager.requestSerializer didChangeValueForKey:@"timeoutInterval"];
AFHTTPRequestOperation *httpOperation = [manager GET:URLString
parameters:parameters
success:^(AFHTTPRequestOperation *operation, id responseObject) {
if (success) {
success(operation, responseObject);
}
}
failure:^(AFHTTPRequestOperation *operation, NSError *error) {
if (failure) {
failure(operation, error);
}
}];
return httpOperation;
}
GET请求
+ (AFHTTPRequestOperation *)POSTMethod:(NSString *)URLString
parameters:(id)parameters
success:(void (^)(AFHTTPRequestOperation *operation, id responseObject))success
failure:(void (^)(AFHTTPRequestOperation *operation, NSError *error))failure {
AFHTTPRequestOperationManager *manager = [AFHTTPRequestOperationManager manager];
manager.requestSerializer = [AFJSONRequestSerializer serializer];
manager.responseSerializer.acceptableContentTypes = [manager.responseSerializer.acceptableContentTypes setByAddingObject:@"text/html"];
// 设置超时时间
[manager.requestSerializer willChangeValueForKey:@"timeoutInterval"];
manager.requestSerializer.timeoutInterval = 10.f;
[manager.requestSerializer didChangeValueForKey:@"timeoutInterval"];
AFHTTPRequestOperation *httpOperation = [manager POST:URLString
parameters:parameters
success:^(AFHTTPRequestOperation *operation, id responseObject) {
if (success) {
success(operation, responseObject);
}
}
failure:^(AFHTTPRequestOperation *operation, NSError *error) {
if (failure) {
failure(operation, error);
}
}];
return httpOperation;
}
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询