Win a copy of The Way of the Web Tester: A Beginner's Guide to Automating Tests this week in the Testing forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

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

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