- android - RelativeLayout 背景可绘制重叠内容
- android - 如何链接 cpufeatures lib 以获取 native android 库?
- java - OnItemClickListener 不起作用,但 OnLongItemClickListener 在自定义 ListView 中起作用
- java - Android 文件转字符串
我正在使用 NSUrlSessionTaskDelegate 将文件上传到服务器,但服务器代码没有在 didCompleteWithError 中返回。这与苹果文档相符:
Server errors are not reported through the error parameter. The only errors your delegate receives through the error parameter are client-side errors, such as being unable to resolve the hostname or connect to the host.
但是有没有其他方法可以得到服务器错误,比如 400 Bad Request 之类的?因为即使我收到错误的请求,现在每个文件上传都是成功的..
最佳答案
像这样的东西应该可以工作。但我没有测试它。它作为答案发布只是因为更简单的代码格式......
- (void)URLSession:(NSURLSession *)session
task:(NSURLSessionTask *)task
didCompleteWithError:(NSError *)error
{
if (!error)
{
NSHTTPURLResponse *response = task.response;
NSLog(@"StatusCode: %d",response.statusCode);
if (response.statusCode != 200) //note that other 2xx codes might be valid
{
//....
}
}
else
{
NSLog(@"Error: %@",error.description);
}
}
关于objective-c - NSUrlSessionTaskDelegate 服务器响应,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34087204/
我刚学会使用 NSURLSession API,我发现我们在创建 session 时只是设置了 NSURLSessionDelegate self.session = [NSURLSession se
我正在尝试将 NSURLSession 与 DataTask 和 Delegate 一起使用,但我找不到一种方法来转换获得的数据通过 didReceiveData 方法转换为字符串。 这是我正在使用的
我正在使用 NSUrlSessionTaskDelegate 将文件上传到服务器,但服务器代码没有在 didCompleteWithError 中返回。这与苹果文档相符: Server errors
我所有的网络代码都依赖于 NSURLSession 委托(delegate)方法——而不是完成处理程序。我的数据和下载任务都很好,但我的上传任务从来没有导致URLSession:task:didCom
我是一名优秀的程序员,十分优秀!