gpt4 book ai didi

html - 如何使用 AFNetworking 获取重定向的 URL?

转载 作者:塔克拉玛干 更新时间:2023-11-01 21:42:51 27 4
gpt4 key购买 nike

我使用 AFNetworking get 方法,url 是这样的:

http://www.hi-pda.com/forum/redirect.php?from=notice&goto=findpost&pid=31089630&ptid=1631932

使用 chrome 我可以看到真实的 URL 是: enter image description here

它在位置。

使用AFNetworking时如何获取url,我试了下面的方法,还是不行

[
manager GET:threadNotice.URLString
parameters:nil
success:^(AFHTTPRequestOperation *operation, id responseObject) {
NSLog(@"%@",[operation.response allHeaderFields]);
}
failure:^(AFHTTPRequestOperation *operation, NSError *error) {

}
];

响应是

2015-05-31 00:11:03.349 HiPDA V2[20006:751020] {
Connection = "keep-alive";
"Content-Encoding" = gzip;
"Content-Type" = "text/html";
Date = "Sat, 30 May 2015 16:10:59 GMT";
Server = "nginx/1.6.2";
"Transfer-Encoding" = Identity;
"X-Powered-By" = "PHP/5.3.10";
}

没有位置字段,我怎样才能得到它?谢谢。

最佳答案

我用下面的方法解决了这个问题:

AFHTTPRequestOperation *requestOperation=[[AFHTTPRequestOperation alloc] initWithRequest:[NSURLRequest requestWithURL:[NSURL URLWithString:_URLString]]];
[requestOperation setRedirectResponseBlock:^NSURLRequest *(NSURLConnection *connection, NSURLRequest *request, NSURLResponse *redirectResponse) {
if (redirectResponse) {
//this is the redirected url
NSLog(@"%@",request.URL);
}
return request;
}];
[requestOperation start];

关于html - 如何使用 AFNetworking 获取重定向的 URL?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30548467/

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