gpt4 book ai didi

java - 在littleproxy中设置远程ip和端口

转载 作者:行者123 更新时间:2023-11-30 03:51:50 25 4
gpt4 key购买 nike

在littleProxy中,如何设置远程IP和端口?他们网站上的示例:

HttpProxyServer server =
DefaultHttpProxyServer.bootstrap()
.withPort(8080)
.start();

仅设置本地端口。

最佳答案

请求目标必须采用绝对形式(如 RFC 7230 第 5.3.2 节所指定),才能由 LittleProxy 转发。以下代码适用于 LittleProxy v1.1.0beta1:

Pattern REQUEST_TARGET_ORIGIN_FORM_PREFIX = Pattern.compile("/[^/]");

@Override
public HttpResponse clientToProxyRequest(HttpObject httpObject) {
if (httpObject instanceof HttpRequest) {
HttpRequest httpRequest = (HttpRequest) httpObject;
if (REQUEST_TARGET_ORIGIN_FORM_PREFIX.matcher(httpRequest.getUri()).lookingAt()) {
String uriRemote = "http://myRemoteHost:myRemotePort" + httpRequest.getUri();
httpRequest.setUri(uriRemote);
}
}
return null;
}

关于java - 在littleproxy中设置远程ip和端口,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24235099/

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