你能否建议一个服务器,我可以测试我的Class发送和接收对httpPost()方法的响应?
答案 0 :(得分:7)
继承人free网站:
http://www.snee.com/xml/crud/posttest.html
您可以使用两个参数将http://www.snee.com/xml/crud/posttest.cgi
作为关键字发布到fname
lname
和<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>
并会显示回复。
表示表格的全部来源
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){}
粗略的你可以去那个网站看看。希望有所帮助
下载一个示例android代码:
{{1}}