Netty HTTP Put Request返回缺少的URL

时间:2013-09-23 08:44:33

标签: java http netty

我正在尝试使用netty创建一个put请求,其代码如下:

    FullHttpRequest request =
            new DefaultFullHttpRequest(HttpVersion.HTTP_1_1, HttpMethod.PUT, uri.toASCIIString());
    HttpHeaders headers = request.headers();
    headers.set(HttpHeaders.Names.HOST, host);
    headers.set(HttpHeaders.Names.CONNECTION, HttpHeaders.Values.KEEP_ALIVE);
    headers.set(HttpHeaders.Names.ACCEPT_ENCODING, HttpHeaders.Values.GZIP + ','
            + HttpHeaders.Values.DEFLATE);

    headers.set(HttpHeaders.Names.CONTENT_TYPE,"text/plain");
    headers.set(HttpHeaders.Names.REFERER, uri.toString());
    headers.set(HttpHeaders.Names.USER_AGENT, "Logentries client side put");
    request.content().writeBytes(msg.getBytes(Charset.forName("ASCII")));
    headers.set(HttpHeaders.Names.CONTENT_LENGTH, request.content().readableBytes());

请求已正确写入服务器,但服务器返回以下错误:

|00000000| 48 54 54 50 2f 31 2e 31 20 34 30 30 20 42 61 64 |HTTP/1.1 400 Bad|
|00000010| 20 52 65 71 75 65 73 74 0d 0a 43 6f 6e 6e 65 63 | Request..Connec|
|00000020| 74 69 6f 6e 3a 20 63 6c 6f 73 65 0d 0a 53 65 72 |tion: close..Ser|
|00000030| 76 65 72 3a 20 6c 6f 67 65 6e 74 72 69 65 73 2f |ver: logentries/|
|00000040| 32 2e 32 2e 31 33 0d 0a 43 6f 6e 74 65 6e 74 2d |2.2.13..Content-|
|00000050| 4c 65 6e 67 74 68 3a 20 34 34 0d 0a 43 6f 6e 74 |Length: 44..Cont|
|00000060| 65 6e 74 2d 54 79 70 65 3a 20 61 70 70 6c 69 63 |ent-Type: applic|
|00000070| 61 74 69 6f 6e 2f 6a 73 6f 6e 0d 0a 0d 0a 7b 22 |ation/json....{"|
|00000080| 72 65 73 70 6f 6e 73 65 22 3a 22 65 72 72 6f 72 |response":"error|
|00000090| 22 2c 22 72 65 61 73 6f 6e 22 3a 22 4d 69 73 73 |","reason":"Miss|
|000000a0| 69 6e 67 20 55 52 4c 22 7d 0a                   |ing URL"}.      |
+--------+-------------------------------------------------+----------------+

为什么它会成为application / json,最重要的是,为什么会丢失url?

0 个答案:

没有答案