This week's giveaway is in the Android forum.
We're giving away four copies of Android Security Essentials Live Lessons and have Godfrey Nolan 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 Android Security Essentials Live Lessons 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: 331
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: 12761
    
    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: 331
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: 1035
    
  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: 331
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
 
Similar Threads
Jersey RESTful web service - How to post XML file using jersey framework
Need to invoke SOAP msg with standalone java class
sample for sending a raw SOAP message to a service?
How to write XML Requests
Send a query to the server from my Java Class