GET 参数值包含逗号,netty 对其进行编码 - 破坏服务
GET parameter value contains comma, netty encodes it - breaking the service
我正在使用一个 Weather.com 网络服务,该服务采用 "latitude,longitude" 值(例如“40.87601089477539,-87.43512725830078”)并使用 Netty 处理网络通信。
服务响应错误,这是由于我的参数值的逗号被转义导致的(即“40.87601089477539%2C-87.43512725830078”)。
# works (when a confidential API key is added)
http://api.weather.com/v2//location?geocode=40.87601089477539,-87.43512725830078
# doesn't work
http://api.weather.com/v2//location?geocode=40.87601089477539%2C-87.43512725830078
转义在com.ning.http.client.RequestBuilderBase.toUrl(boolean encode)
中完成。如果我能够将 false 传递给它,那么我的问题就会得到解决,但调用此方法的是 Netty 库而不是我,并且该选项是硬编码的。
1) 是否有针对 Netty 消费者的解决方法? 2) 解决此问题的正确方法是什么?
编辑 其他详细信息
堆栈跟踪:
RequestBuilderBase$RequestImpl.toUrl(boolean) line: 166
RequestBuilderBase$RequestImpl.getUrl() line: 118
RequestBuilderBase$RequestImpl.<init>(Request) line: 78
RequestBuilder(RequestBuilderBase<T>).<init>(Class<T>, Request) line: 323
RequestBuilder.<init>(Request) line: 42
NettyAsyncHttpProvider$HttpProtocol.handle(ChannelHandlerContext, MessageEvent) line: 2115
NettyAsyncHttpProvider.messageReceived(ChannelHandlerContext, MessageEvent) line: 1128
NettyAsyncHttpProvider(SimpleChannelUpstreamHandler).handleUpstream(ChannelHandlerContext, ChannelEvent) line: 75
DefaultChannelPipeline.sendUpstream(DefaultChannelPipeline$DefaultChannelHandlerContext, ChannelEvent) line: 564
DefaultChannelPipeline$DefaultChannelHandlerContext.sendUpstream(ChannelEvent) line: 792
ChunkedWriteHandler.handleUpstream(ChannelHandlerContext, ChannelEvent) line: 141
DefaultChannelPipeline.sendUpstream(DefaultChannelPipeline$DefaultChannelHandlerContext, ChannelEvent) line: 564
DefaultChannelPipeline$DefaultChannelHandlerContext.sendUpstream(ChannelEvent) line: 792
HttpContentDecompressor(HttpContentDecoder).messageReceived(ChannelHandlerContext, MessageEvent) line: 100
HttpContentDecompressor(SimpleChannelUpstreamHandler).handleUpstream(ChannelHandlerContext, ChannelEvent) line: 75
DefaultChannelPipeline.sendUpstream(DefaultChannelPipeline$DefaultChannelHandlerContext, ChannelEvent) line: 564
DefaultChannelPipeline$DefaultChannelHandlerContext.sendUpstream(ChannelEvent) line: 792
Channels.fireMessageReceived(ChannelHandlerContext, Object, SocketAddress) line: 296
HttpClientCodec$Decoder(ReplayingDecoder<T>).unfoldAndFireMessageReceived(ChannelHandlerContext, Object, SocketAddress) line: 600
HttpClientCodec$Decoder(ReplayingDecoder<T>).callDecode(ChannelHandlerContext, Channel, ChannelBuffer, ChannelBuffer, SocketAddress) line: 584
HttpClientCodec$Decoder(ReplayingDecoder<T>).messageReceived(ChannelHandlerContext, MessageEvent) line: 445
HttpClientCodec$Decoder(SimpleChannelUpstreamHandler).handleUpstream(ChannelHandlerContext, ChannelEvent) line: 75
HttpClientCodec.handleUpstream(ChannelHandlerContext, ChannelEvent) line: 92
DefaultChannelPipeline.sendUpstream(DefaultChannelPipeline$DefaultChannelHandlerContext, ChannelEvent) line: 564
DefaultChannelPipeline.sendUpstream(ChannelEvent) line: 559
Channels.fireMessageReceived(Channel, Object, SocketAddress) line: 268
Channels.fireMessageReceived(Channel, Object) line: 255
NioWorker.read(SelectionKey) line: 94
NioWorker(AbstractNioWorker).processSelectedKeys(Set<SelectionKey>) line: 372
NioWorker(AbstractNioWorker).run() line: 246
NioWorker.run() line: 38
ThreadRenamingRunnable.run() line: 102
DeadLockProofWorker.run() line: 42
ThreadPoolExecutor.runWorker(ThreadPoolExecutor$Worker) line: 1142
ThreadPoolExecutor$Worker.run() line: 617 [local variables unavailable]
Thread.run() line: 745 [local variables unavailable]
为了回答我自己的问题,public 图书馆中的 none 是罪魁祸首。您可以设置一个标志来防止编码 (setUseRawUrl(true)
):
AsyncHttpClient asyncHttpClient = new AsyncHttpClient(
new AsyncHttpClientConfig.Builder()
.setUseRawUrl(true)
.build());
Future<Response> f = asyncHttpClient.prepareGet(url).execute();
Response r = f.get();
我正在使用一个 Weather.com 网络服务,该服务采用 "latitude,longitude" 值(例如“40.87601089477539,-87.43512725830078”)并使用 Netty 处理网络通信。
服务响应错误,这是由于我的参数值的逗号被转义导致的(即“40.87601089477539%2C-87.43512725830078”)。
# works (when a confidential API key is added)
http://api.weather.com/v2//location?geocode=40.87601089477539,-87.43512725830078
# doesn't work
http://api.weather.com/v2//location?geocode=40.87601089477539%2C-87.43512725830078
转义在com.ning.http.client.RequestBuilderBase.toUrl(boolean encode)
中完成。如果我能够将 false 传递给它,那么我的问题就会得到解决,但调用此方法的是 Netty 库而不是我,并且该选项是硬编码的。
1) 是否有针对 Netty 消费者的解决方法? 2) 解决此问题的正确方法是什么?
编辑 其他详细信息
堆栈跟踪:
RequestBuilderBase$RequestImpl.toUrl(boolean) line: 166
RequestBuilderBase$RequestImpl.getUrl() line: 118
RequestBuilderBase$RequestImpl.<init>(Request) line: 78
RequestBuilder(RequestBuilderBase<T>).<init>(Class<T>, Request) line: 323
RequestBuilder.<init>(Request) line: 42
NettyAsyncHttpProvider$HttpProtocol.handle(ChannelHandlerContext, MessageEvent) line: 2115
NettyAsyncHttpProvider.messageReceived(ChannelHandlerContext, MessageEvent) line: 1128
NettyAsyncHttpProvider(SimpleChannelUpstreamHandler).handleUpstream(ChannelHandlerContext, ChannelEvent) line: 75
DefaultChannelPipeline.sendUpstream(DefaultChannelPipeline$DefaultChannelHandlerContext, ChannelEvent) line: 564
DefaultChannelPipeline$DefaultChannelHandlerContext.sendUpstream(ChannelEvent) line: 792
ChunkedWriteHandler.handleUpstream(ChannelHandlerContext, ChannelEvent) line: 141
DefaultChannelPipeline.sendUpstream(DefaultChannelPipeline$DefaultChannelHandlerContext, ChannelEvent) line: 564
DefaultChannelPipeline$DefaultChannelHandlerContext.sendUpstream(ChannelEvent) line: 792
HttpContentDecompressor(HttpContentDecoder).messageReceived(ChannelHandlerContext, MessageEvent) line: 100
HttpContentDecompressor(SimpleChannelUpstreamHandler).handleUpstream(ChannelHandlerContext, ChannelEvent) line: 75
DefaultChannelPipeline.sendUpstream(DefaultChannelPipeline$DefaultChannelHandlerContext, ChannelEvent) line: 564
DefaultChannelPipeline$DefaultChannelHandlerContext.sendUpstream(ChannelEvent) line: 792
Channels.fireMessageReceived(ChannelHandlerContext, Object, SocketAddress) line: 296
HttpClientCodec$Decoder(ReplayingDecoder<T>).unfoldAndFireMessageReceived(ChannelHandlerContext, Object, SocketAddress) line: 600
HttpClientCodec$Decoder(ReplayingDecoder<T>).callDecode(ChannelHandlerContext, Channel, ChannelBuffer, ChannelBuffer, SocketAddress) line: 584
HttpClientCodec$Decoder(ReplayingDecoder<T>).messageReceived(ChannelHandlerContext, MessageEvent) line: 445
HttpClientCodec$Decoder(SimpleChannelUpstreamHandler).handleUpstream(ChannelHandlerContext, ChannelEvent) line: 75
HttpClientCodec.handleUpstream(ChannelHandlerContext, ChannelEvent) line: 92
DefaultChannelPipeline.sendUpstream(DefaultChannelPipeline$DefaultChannelHandlerContext, ChannelEvent) line: 564
DefaultChannelPipeline.sendUpstream(ChannelEvent) line: 559
Channels.fireMessageReceived(Channel, Object, SocketAddress) line: 268
Channels.fireMessageReceived(Channel, Object) line: 255
NioWorker.read(SelectionKey) line: 94
NioWorker(AbstractNioWorker).processSelectedKeys(Set<SelectionKey>) line: 372
NioWorker(AbstractNioWorker).run() line: 246
NioWorker.run() line: 38
ThreadRenamingRunnable.run() line: 102
DeadLockProofWorker.run() line: 42
ThreadPoolExecutor.runWorker(ThreadPoolExecutor$Worker) line: 1142
ThreadPoolExecutor$Worker.run() line: 617 [local variables unavailable]
Thread.run() line: 745 [local variables unavailable]
为了回答我自己的问题,public 图书馆中的 none 是罪魁祸首。您可以设置一个标志来防止编码 (setUseRawUrl(true)
):
AsyncHttpClient asyncHttpClient = new AsyncHttpClient(
new AsyncHttpClientConfig.Builder()
.setUseRawUrl(true)
.build());
Future<Response> f = asyncHttpClient.prepareGet(url).execute();
Response r = f.get();