【发布时间】:2015-02-23 09:37:28
【问题描述】:
是否有人已经尝试为 GET 请求实现处理程序(对于 POST 方法的问题相同)而不使用包含的(并且很酷的)GCDWebUploader?
我需要服务器响应 GET 请求 http://local/download/filename.ext 将文件上传到客户端。
我使请求符合代码“BackgroundSessionManager”(可在此处获得:AFNetworking 2.0 and background transfers),它会被发送并触发,不用担心。
我得到服务器端的日志是这样的:
[DEBUG] Did start background task
[DEBUG] Connection received 248 bytes on socket 14
[DEBUG] Connection on socket 14 preflighting request "GET /download/file.ext with 248 bytes body
[DEBUG] Connection on socket 14 processing request "GET /download/file.ext" with 248 bytes body
[EXCEPTION] *** +[NSJSONSerialization dataWithJSONObject:options:error:]: value parameter is nil
[DEBUG] Did close connection on socket 14
我不知道如何设置处理程序以便不关心从 JSON 解析的不存在的查询。
[webServer addHandlerForMethod:@"GET" path:@"/download" requestClass:[GCDWebServerRequest class] processBlock:^GCDWebServerResponse *(GCDWebServerRequest* request) {
__strong AppDelegate* strongSelf = weakSelf;
NSLog(@"request for download is %@", request);
return [strongSelf downloadFile:request];
}];
【问题讨论】:
-
看起来您正在使用或向 GCDWebUploader 实例添加处理程序,而不是使用 GCDWebServer 实例。这将解释 NSJSONSerialization 异常。
标签: ios afnetworking-2 file-transfer backgrounding gcdwebserver