Win a copy of Cross-Platform Desktop Applications: Using Node, Electron, and NW.js this week in the JavaScript forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

Java URL class request receives status code 400 for valid URL request  RSS feed

Sanjay Virkar
Posts: 19
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Through my Java program (which uses URL class) I am trying to access USPS RateCalculator service to obtain shipping rate for a given mail package with given specifications (embeded in my XML request like weight, length, height...etc.)

USPS expects the whole request to be sent as XML and in return, it sends shipping rate in the form of XML as response.

When I run my Java program from command line, I get response 400 from USPS server. Before making request to USPS, I print the entire request on screen. If I cut and paste this printed request in the browser, I get proper XML response back.

Also, to make sure that my Java program is working properly, when I replace the URL- i.e. 'myurl' in my code with '', I get propper response with complete HTML. So code is working fine.

Offcourse browser and command line through which I am running my java program are on the same computer and hence same network.

This behaviour is really puzzling........any ideas?
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!