aspose file tools*
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 Soft Skills this week in the Jobs Discussion 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: 418
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: 12835
    
    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: 418
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: 1110
    
  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: 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: 418
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