I am trying to build and HTTP request to our Rackspace CDN
I need to add a Json string as content to give the login instructions
I used curl to test the info and it works but through Netty I get a 400 Bad Request response which tells me I am not passing the Json correctly all the example on Github are overconvoluted and the ones in stack overflow are for version 3 any help would be greatly appreciated here is my code I am using 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);
And I get the following response which tells me I connected with the server but my request was not formed properly
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>
All sugestions welcome
After the usual too many hours I found the solution here it is works with Netty 4.1.0.Beta5 Request composition
and here is the Initializer