• Post Reply Bookmark Topic Watch Topic
  • New Topic

Getting HTTP 400 returned - having trouble figuring out why

 
Edward Fultz
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I have the code below that is returning HTTP 400 error. URL works in chrome browser but when run in IE or Firefox both browsers act as if the data returned is RSS stream. It is not - it is XML data being returned. When the get input stream statement runs the IOException is caught. I have looked at the error stream but it is null. Is there something more I have to add to ensure the connection knows XML data is being returned?

String strURL = ""http://165.113.16.5:8581/odata/api/devices";
DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
DocumentBuilder builder = factory.newDocumentBuilder();
URL url = new URL(strURL);
HttpURLConnection connection = (HttpURLConnection) url.openConnection();
connection.setRequestProperty("Authorization", "Basic " + new String(new Base64().encode((strUserName + ":" + strPassword).getBytes())));
Document document = builder.parse(connection.getInputStream());
 
Edward Fultz
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I added code to display the header fields and received the following - they appear to be correct - especially content type showing application/xml:

Key : null ,Value : [HTTP/1.1 400 Bad Request]
Key : Server ,Value : [Jetty(7.6.7.v20120910)]
Key : Set-Cookie ,Value : [JSESSIONID=1l0m65qunpa7ic1rffwzqg2x3;Path=/]
Key : Expires ,Value : [Thu, 01 Jan 1970 00:00:00 GMT]
Key : Content-Length ,Value : [243]
Key : Date ,Value : [Mon, 14 Dec 2015 18:02:17 GMT]
Key : DataServiceVersion ,Value : [1.0]
Key : Content-Type ,Value : [application/xml]
 
Ron McLeod
Saloon Keeper
Posts: 1263
131
Android Angular Framework Eclipse IDE Java Linux MySQL Database Redhat TypeScript
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You should probably be looking at what you are sending, rather than what you are receiving. A 400 usally means that the information that you have sent (contained in headers and/or payload) is either corrupt, invalid, or missing something critical.

If you have had sucess using other clients, capture the network traffic for working and non-working scenarios and compare to see what the differences are.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!