データを送受信するNetty httpサーバーを作成するときに問題があります。 誰かの助けや説明に感謝します。Netty - Http、Webブラウザ、Webページで何も耳にしません
このような私のクライアント(HTML)コード:
>
$.ajax({
type : "POST",
url : "http://localhost:9999/MyTest/",
data : {"servicename":"aptest","querymsg":{"wsid":"111" ,"telid":"1111","role":"1"}},
dataType:"json",
timeout:100000,
beforeSend: function(xhr) { //add header data
},
success: function(rs) {
alert("[success]" + rs);
},
complete:function(XMLHttpRequest,textStatus){
if(XMLHttpRequest.readyState=="4"){
alert(XMLHttpRequest.responseText);
}
},
error: function(XMLHttpRequest,textStatus,errorThrown){
alert("error:"+textStatus);
}
});
サーバー側のコード:
ServerBootstrap bootstrap = new ServerBootstrap(new NioServerSocketChannelFactory(
Executors.newCachedThreadPool(),
Executors.newCachedThreadPool())
);
HttpServerPipelineFactory pipeline = new HttpServerPipelineFactory();
bootstrap.setPipelineFactory(pipeline);
serverChannel = bootstrap.bind(new InetSocketAddress(Port));
HttpRequestServerHandler:
BLOCKQUOTE
HttpResponse res = new DefaultHttpResponse(HTTP_1_1, HttpResponseStatus.OK);
res.setContent(
ChannelBuffers.copiedBuffer(
"Test", CharsetUtil.UTF_8));
setContentLength(res, res.getContent().readableBytes());
res.setChunked(true);
res.setHeader(HttpHeaders.Names.CONTENT_TYPE, "text/html; charset=UTF-8");
// Send the response and close the connection if necessary.
ChannelFuture f = ctx.getChannel().write(res);
エラーとは何ですか? – Veebs
エラーはありませんが、ブラウザ側では、コンテンツが[成功]であることを警告します。 – user1213496