Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Where can I test my httpPost method?

Could you please advice a Server against which I can test my Class which sends and receives a response to httpPost() method?

like image 634
Eugene Avatar asked Dec 27 '10 18:12

Eugene


1 Answers

Heres a free site:

http://www.snee.com/xml/crud/posttest.html

You can post to http://www.snee.com/xml/crud/posttest.cgiwith two parameters put them as your key

fname and lname and will display the response.

Heres the entire source of the form

<html> 
<title>POST test</title> 
<body> 

<h1>posttest.html</h1> 

<form action="posttest.cgi" method="post"> 
<p>This form invokes an existing script called posttest.cgi:</p> 

<p>first name <input type="text" name="fname" size="40"/></p> 
<p>last name <input type="text" name="lname" size="40"/></p> 

<input type="submit" value="  go  " /> 

</form> 

</body></html>

Of coarse you can go to that site and check it out. Hope that helps

Heres a sample android code:

try{
HttpClient client = new DefaultHttpClient();
HttpPost request = new HttpPost(
"http://www.snee.com/xml/crud/posttest.cgi");

List<NameValuePair> postParameters = new ArrayList<NameValuePair>();

postParameters.add(new BasicNameValuePair("fname", "First name"));
postParameters.add(new BasicNameValuePair("lname", "Last name"));

UrlEncodedFormEntity formEntity = new UrlEncodedFormEntity(
postParameters);

request.setEntity(formEntity);

HttpResponse response = client.execute(request);

in = new BufferedReader(new InputStreamReader(response.getEntity()
.getContent()));

StringBuffer sb = new StringBuffer("");
String line = "";
String NL = System.getProperty("line.separator");
while ((line = in.readLine()) != null) {
sb.append(line + NL);
}
in.close();}catch(Exception ex){}
like image 94
Shardul Avatar answered Sep 20 '22 00:09

Shardul