我一直在玩Littleproxy,发现很容易修改回复,但无法获得修改请求参数的任何好例子。
在网上我发现只有一个例子,即修改帖子数据。但无法使其发挥作用。
您是否有一个示例说明我们如何获取请求参数并对其进行修改。
我有这个:
public HttpResponse proxyToServerRequest(HttpObject httpObject) {
if(httpObject instanceof FullHttpRequest){
FullHttpRequest request = (FullHttpRequest) httpObject;
if(request.getMethod() == HttpMethod.POST
&& request.getUri().contains("/post")){
CompositeByteBuf contentBuf = (CompositeByteBuf) request.content();
String contentStr = contentBuf.toString(CharsetUtil.UTF_8);
System.out.println("Post content for " + request.getUri() + " : " + contentStr);
String newBody = contentStr.replace("e", "ei");
ByteBuf bodyContent = Unpooled.copiedBuffer(newBody, CharsetUtil.UTF_8);
contentBuf.clear().writeBytes(bodyContent);
HttpHeaders.setContentLength(request, newBody.length());
}
}
return null;
}
你知道其他任何好的例子吗?
答案 0 :(得分:0)
您可以删除这样的特定标题:
@Override
public HttpResponse proxyToServerRequest(HttpObject httpObject)
{
if (httpObject instanceof HttpMessage)
{
HttpHeaders headers = ((HttpMessage)httpObject).headers();
headers.names().forEach(h -> headers.remove(headerName));
}
return super.proxyToServerRequest(httpObject);
}