1

I need to add a header ("correlationIdHeader") to a GET Request using Java's HttpUrlConnection. However the server (IBM Http Server - built on Apache) answers with a 400 Error and the following info:

Request header field is missing ':' separator

My code:

HttpURLConnection conn = (HttpURLConnection)url.openConnection();
conn.setRequestProperty("correlationIdHeader", UUID.randomUUID().toString());
conn.setRequestMethod(HttpMethod.GET.name());
conn.setRequestProperty("Accept", contentType);

int responseCode= conn.getResponseCode();

Any idea what could be happening here?

EDIT: it has to do with UUID.randomUUID().toString(). I don't know why but it doesn't like UUID's format. Why?

codependent
  • 23,193
  • 31
  • 166
  • 308
  • I would try putting the setRequestMethod before setting the first property but I don't really know if that is the problem. – selalerer Feb 04 '15 at 12:20
  • What does the UUID looks like? Does it have a space in it or some other special character? – selalerer Feb 04 '15 at 12:21
  • Tried moving requestMethod but didn't work. UUID is something like this: 00000000-0000-0000-C000-000000000046. http://en.wikipedia.org/wiki/Universally_unique_identifier – codependent Feb 04 '15 at 12:22
  • You could try and see that is actually being sent with wireshark or by writing a simple server yourself. – selalerer Feb 04 '15 at 12:38
  • 1
    This can help seeing what is sent on the wire: http://stackoverflow.com/questions/1445919/how-to-enable-wire-logging-for-a-java-httpurlconnection-traffic – selalerer Feb 04 '15 at 12:42

0 Answers0