Post and Get Methods

I can get Post's to work, but Get Methods are not working out so w

Page 1 of 1

2 Replies - 602 Views - Last Post: 17 September 2009 - 03:39 PM Rate Topic: -----

#1 painkiller102  Icon User is offline

  • D.I.C Regular
  • member icon

Reputation: 15
  • View blog
  • Posts: 281
  • Joined: 27-February 08

Post and Get Methods

Post icon  Posted 17 September 2009 - 01:12 PM

I have been trying to make my program access a site (non-in particular yet, the sites I've done so far were testing), send information, and then retrieve whats being sent back. I am using the org.apache.commons.httpclient api / Jar(s) for this project, and i cant seem to get the "Get" Method to work right. The following code works on sites using "Post" html methods:
public void Post(String url)
{

		HttpClient client = new HttpClient();
		PostMethod method = new PostMethod(url);
		method.addParameter("q","italy");//the site i was testing was a search site
		method.addParameter("submit","go!");//the go button
	  
		int statusCode = client.executeMethod( method );//executes and send the information
		if( statusCode != -1 )
		{
			String contents = method.getResponseBodyAsString();
			System.out.println(contents);
			method.releaseConnection();
		}
}



The main problem is that i need to access sites that use the "Get method" as well, however i cannot seem to find a good tutorial on this and when i do, it never seems to work correctly. And on top of it (to add to my confusion), the GetMethod() from Apache doesn't seem to have an .addParameter() feature for me to pass parameters to IE: "search","Italy". Any information would be greatly appreciated and thanks for viewing!

Is This A Good Question/Topic? 0
  • +

Replies To: Post and Get Methods

#2 DaneAU  Icon User is offline

  • Great::Southern::Land
  • member icon

Reputation: 284
  • View blog
  • Posts: 1,615
  • Joined: 15-May 08

Re: Post and Get Methods

Posted 17 September 2009 - 03:10 PM

Open and output stream and input stream, send a string with GET through the output stream to the URL / URI and listen for the response using an input stream.

I did have an example to show this, i will try to dish it out
Was This Post Helpful? 0
  • +
  • -

#3 painkiller102  Icon User is offline

  • D.I.C Regular
  • member icon

Reputation: 15
  • View blog
  • Posts: 281
  • Joined: 27-February 08

Re: Post and Get Methods

Posted 17 September 2009 - 03:39 PM

View Postbbq, on 17 Sep, 2009 - 02:10 PM, said:

Open and output stream and input stream, send a string with GET through the output stream to the URL / URI and listen for the response using an input stream.

I did have an example to show this, i will try to dish it out


ok... so i get the opening the input stream and outputstream, however what do you mean by send a string "with" get?
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1