java - 如何在 AsyncHttpClient 中停止重定向并获得响应
问题描述
我有一个HTTP GET
返回状态200
和一些响应。此响应是重定向的结果。
如果我asyncHttpClient.setEnableRedirects(false);
在我的代码中引入,那么重定向停止并且它以状态 302 失败。但是在我的应用程序中,这个状态 302 和与之关联的响应是我需要的。
我正在网上搜索并试图弄清楚,但我是 Java 新手,所以无法理解如何实现这一点。
我想要的是,当服务器返回状态 302 时,我想触发 onSuccess 并捕获响应。谢谢。
解决方案
If I'm getting right what do you need then you could implement your own AsyncHandlers to react with a different AsyncHandler.State for 302 status code. ( https://github.com/AsyncHttpClient/async-http-client#using-custom-asynchandlers) or while creating the client stop to follow redirects like this:
asyncHttpClient(config().setFollowRedirect(false))
(it might be different from the approach you mentioned above.)
P.S. I'm using 2.5.2 version of the asynchttpclient lib.
推荐阅读
- javascript - Rails 项目:为什么我的 javascript 文件被忽略?
- java - 每当我退出时应用程序崩溃
- html - Angular:结合几个订阅
- javascript - nodejs应用程序中的PDF到HTML
- javascript - 显示/隐藏元素时出现电话号码正则表达式验证错误
- angular - 如何使用来自 RxJS 可观察订阅调用的值
- google-apps-script - 使用 Google Apps 脚本检查播放列表中是否存在 YouTube 视频
- wordpress - htaccess 重写 laravel 路由到 lv.php 和 wordpress 路由到 index.php
- python - 带有歌曲队列的 Python 不和谐音乐机器人
- python - 为什么不使用python函数内部的变量值