This week's book giveaways are in the Java EE and JavaScript forums.
We're giving away four copies each of The Java EE 7 Tutorial Volume 1 or Volume 2(winners choice) and jQuery UI in Action and have the authors on-line!
See this thread and this one 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 The Java EE 7 Tutorial Volume 1 or Volume 2 this week in the Java EE forum
or jQuery UI in Action in the JavaScript 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: 336
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: 12769
    
    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: 336
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
Ranch Hand

Joined: Aug 27, 2012
Posts: 1044
    
  10

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: 4646
    
    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: 336
It works now.

Many Thanks
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Sending a request to the server using POST