gpt4 book ai didi

Java LittleProxy(在 Netty 之上): How to access the POST Body data?

转载 作者:行者123 更新时间:2023-11-30 10:42:27 34 4
gpt4 key购买 nike

我遵循了显示的简单示例 GitHub:LittleProxy并在 clientToProxyRequest(HttpObject httpObject) 方法中添加了以下内容。

public HttpResponse clientToProxyRequest(HttpObject httpObject)
{
if(httpObject instanceof DefaultHttpRequest)
{
DefaultHttpRequest httpRequest = (DefaultHttpRequest)httpObject;
logger.info(httpRequest.getUri());
logger.info(httpRequest.toString());

// How to access the POST Body data?
HttpPostRequestDecoder d = new HttpPostRequestDecoder(httpRequest);
d.getBodyHttpDatas(); //NotEnoughDataDecoderException
}
return null;
}

记录器报告这个,IMO 只有这两个标题在这里相关。这是一个 POST 请求,并且有内容......

POST http://www.... HTTP/1.1
Content-Length: 522

查看 Netty API 文档,HttpPostRequestDecoder 似乎很有前途,但我得到了一个 NotEnoughDataDecoderException。在 Netty JavaDoc写了这个,不知道怎么提供数据?

This getMethod returns a List of all HttpDatas from body. If chunked, all chunks must have been offered using offer() getMethod. If not, NotEnoughDataDecoderException will be raised.

事实上,我也不确定这是否是在代理中获取 POST 数据的正确方法。

最佳答案

尝试将此添加到您的 HttpFiltersSourceAdapter 中以避免 NotEnoughDataDecoderException:

@Override
public int getMaximumRequestBufferSizeInBytes() {
return 1048576;
}

1048576 这里是聚合内容的最大长度。参见 POSTing data to netty with Apache HttpClient .

这将启用内容的解压缩和聚合,请参阅 org.littleshoot.proxy.impl.ClientToProxyConnection 中的源代码:

// Enable aggregation for filtering if necessary
int numberOfBytesToBuffer = proxyServer.getFiltersSource()
.getMaximumRequestBufferSizeInBytes();
if (numberOfBytesToBuffer > 0) {
aggregateContentForFiltering(pipeline, numberOfBytesToBuffer);
}

关于Java LittleProxy(在 Netty 之上): How to access the POST Body data?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38130224/

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