Ian*_*ink 34 iphone xamarin.ios http-response-codes ios nsurlconnectiondelegate
在iOS中,如何从Web服务器接收响应的http状态代码(404,500 200等).我假设它在NSUrlConnectionDelegate中.
Objective-C或Monotouch .NET回答好.
Vla*_*mir 87
是的,您可以在委托方法-didRecieveResponse中获取状态代码:
- (void) connection:(NSURLConnection *)connection didReceiveResponse:(NSURLResponse *)response{
NSHTTPURLResponse* httpResponse = (NSHTTPURLResponse*)response;
int code = [httpResponse statusCode];
}
Run Code Online (Sandbox Code Playgroud)
Man*_*uel 11
NSHTTPURLResponse* urlResponse = nil;
NSError *error = nil;
responseData = [NSURLConnection sendSynchronousRequest:request returningResponse:&urlResponse error:&error];
Run Code Online (Sandbox Code Playgroud)
aSynchronous请求也应该有办法获取NSHTTPURLResponse ..
你得到这样的状态代码:
int statusCode = [urlResponse statusCode];
int errorCode = error.code;
Run Code Online (Sandbox Code Playgroud)
在一些使用过多的错误代码(如404)的情况下,它将被置于错误中,但使用不同的代码(401将为-1012).
归档时间: |
|
查看次数: |
34263 次 |
最近记录: |