我正在尝试向我们的 Rackspace CDN 构建和 HTTP 请求
我需要添加一个 Json 字符串作为内容以提供登录说明
我使用 curl 来测试信息并且它可以工作,但是通过 Netty 我得到一个 400 Bad Request 响应,这告诉我我没有正确传递 Json Github 上的所有示例都过于复杂,堆栈溢出中的示例适用于版本 3,任何帮助都会非常感谢这里是我使用 Netty 4.1.0Beta5 的代码
URI uri = new URI("https://identity.api.rackspacecloud.com");
HttpDataFactory factory = new DefaultHttpDataFactory(
DefaultHttpDataFactory.MINSIZE);
HttpPostRequestEncoder bodyRequestEncoder = new
HttpPostRequestEncoder(factory, request, false);
HttpHeaders headers = request.headers();
headers.set(HttpHeaderNames.HOST,
"https://identity.api.rackspacecloud.com/v2.0/tokens");
headers.set(HttpHeaderNames.CONTENT_TYPE, new
AsciiString("application/json"));
String json = "{\"auth\":{\"RAX-KSKEY:apiKeyCredentials\":{\"username
\":\"AAsdFrank\",\"apiKey\":\"adfadfdadsf33434fdfdfdfaf\"}}}";
ByteBuf buffer= Unpooled.copiedBuffer(json, CharsetUtil.UTF_8);
headers.set(HttpHeaderNames.CONTENT_LENGTH,
String.valueOf(buffer.readableBytes()));
bodyRequestEncoder.addBodyAttribute("json", json);
request = bodyRequestEncoder.finalizeRequest();
io.netty.channel.Channel channel =
cdnBootstrap.connect("identity.api.rackspacecloud.com",
443).sync().channel();
channel.writeAndFlush(request);
我收到以下响应,告诉我我已连接到服务器,但我的请求没有正确形成
STATUS: 400 Bad Request
VERSION: HTTP/1.1
HEADER: Connection = close
HEADER: Content-Length = 166
HEADER: Content-Type = text/html
HEADER: Date = Thu, 25 Jun 2015 22:10:20 GMT
HEADER: Server = nginx
CONTENT {
<html>
<head><title>400 Bad Request</title></head>
<body bgcolor="white">
<center><h1>400 Bad Request</h1></center>
<hr><center>nginx</center>
</body>
</html>
欢迎所有建议