How can I get httparty to work with Glassfish? Getting 400 BadRequest response
Question
Using: Glassfish v3. Httparty 0.6.1 & 0.5.2.
I'm starting glassfish using "mvn glassfish:run" (maven-glassfish-plugin) Everything works in the application.
This url works in RESTClient, cURL, and in the browser, but when I try with httpparty at the command line, I get this:
$> httparty -v "http://localhost:8080/parakeet/tickets/111"
GET http://localhost:8080/parakeet/tickets/111
400 BadRequest
content-type: text/plain; charset=iso-8859-1
connection: close
date: Fri, 30 Jul 2010 19:15:34 GMT
content-length: 0
I figure it's because of a header or something. I've tried using httparty to send the following headers:
-H "Content-type":"application/json" -H "charset":"UTF-8" -H "Accept":"*/*"
And all combinations of the above, including
-H "Content-type":"application/json; charset=UTF-8"
Any thoughts?
Solution
Apparrently Glassfish requires a "User-Agent" header. It's working with anything, just as long as it is set. This works (ripped from Chrome's resource panel):
httparty -v -H "User-Agent":"Mozilla/5.0 (Macintosh; U; Intel Mac OS X 10_5_8; en-US) AppleWebKit/533.4 (KHTML, like Gecko) Chrome/5.0.375.125 Safari/533.4" http://localhost:8080/parakeet/tickets/34
As does this
httparty -v -H "User-Agent":"Commander Cool" http://localhost:8080/parakeet/tickets/34
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow