This week's book giveaway is in the Android forum.
We're giving away four copies of Head First Android and have Dawn & David Griffiths on-line!
See this thread for details.
The moose likes Java in General and the fly likes Sending a request to the server using POST Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Head First Android this week in the Android forum!
JavaRanch » Java Forums » Java » Java in General
Bookmark "Sending a request to the server using POST" Watch "Sending a request to the server using POST" New topic
Author

Sending a request to the server using POST

Isaac Ferguson
Ranch Hand

Joined: Jun 22, 2012
Posts: 560
Hi

I am trying to send a request to the Google server, using this code:



I have read 300 times the query and I think all is correct

I get the error:




Any idea please?

Many Thanks
William Brogden
Author and all-around good cowpoke
Rancher

Joined: Mar 22, 2000
Posts: 12982
    
    5
You are encoding the parameters in the URL - that is for GET operations. Why do you think you need the POST method?

Bill
(400 = request syntactically incorrect)
Isaac Ferguson
Ranch Hand

Joined: Jun 22, 2012
Posts: 560
Hi Bill,

I am using a POST method because GA launches the "405 invalid method error" if you don´t use it.

Then what way must I encode the URL as String?

Many Thanks,
Richard Tookey
Rancher

Joined: Aug 27, 2012
Posts: 1166
    
  17

Angus Ferguson wrote:Hi Bill,

I am using a POST method because GA launches the "405 invalid method error" if you don´t use it.

Then what way must I encode the URL as String?

Many Thanks,


For POST the parameters are sent as the body of the request and not as part of the URL.
Pat Farrell
Rancher

Joined: Aug 11, 2007
Posts: 4659
    
    5

Plus, its better to use a well documented and well tested library, such as the Apache HTTP client software than to write your own. You will get the mainline code to work, but there are lots of edge cases that someone else has solved before you even start.
Isaac Ferguson
Ranch Hand

Joined: Jun 22, 2012
Posts: 560
It works now.

Many Thanks
 
wood burning stoves
 
subject: Sending a request to the server using POST
 
It's not a secret anymore!