gpt4 book ai didi

objective-c - AF网络检查响应

转载 作者:行者123 更新时间:2023-12-03 17:50:07 24 4
gpt4 key购买 nike

如何检查响应是否返回:

HTTP/1.1 302 Moved Temporarily

Server: nginx/1.5.6

Date: Wed, 18 Mar 2015 19:23:02 GMT

Content-Type: text/html

Transfer-Encoding: chunked

Connection: keep-alive

Last-Modified: Wed, 18 Mar 2015 19:23:02 GMT

Set-Cookie: PHPSESSID=1oh16nbnn9anin3r71tcsmo804; path=/

Expires: Thu, 19 Nov 1981 08:52:00 GMT

Cache-Control: no-store, no-cache, must-revalidate, post-check=0, pre-check=0

Pragma: no-cache

Set-Cookie: er_referer=deleted; expires=Thu, 01-Jan-1970 00:00:01 GMT

Set-Cookie: S_ID=1061662561; path=/

Location: /core/

请求代码:

AFHTTPRequestOperationManager *manager = [AFHTTPRequestOperationManager manager];
manager.responseSerializer = [AFHTTPResponseSerializer serializer];
AFHTTPRequestSerializer * requestSerializer = [AFHTTPRequestSerializer serializer];
[requestSerializer setValue:ua forHTTPHeaderField:@"User-Agent"];
manager.requestSerializer = requestSerializer;
AFHTTPResponseSerializer * responseSerializer = [AFHTTPResponseSerializer serializer];
manager.responseSerializer = responseSerializer;
NSDictionary *parameters = @{@"login": myLogin, @"pass": myPassword};
[manager POST:urlLogin parameters:parameters success:^(AFHTTPRequestOperation *operation, id responseObject) {
if ([operation.responseString rangeOfString:@""].location == NSNotFound) {
NSLog(@"Login or password false");
} else {

如果响应html我这样做if([operation.responseString rangeOfString:@"Then I put the title"].Location == NSNotFound),但不知道如何在这种情况下做

最佳答案

Foundation URL 加载系统会自动将您的请求重定向到 Location header 中指定的路径。

如果您需要拦截重定向(通常是为了处理身份验证问题),您可以在 操作 对象上设置身份验证质询 block (如果需要,还可以设置重定向响应 block )。

Here's an AFNetworking GitHub issue其中讨论了这个问题。如果您需要的话,它有一些示例代码。

关于objective-c - AF网络检查响应,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29131211/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com