此发布请求转到连接到我的数据库的 php 页面,该页面查询文本字段“名称”中的任何内容。当我知道它们不为空时,附加到结果的字符串始终为空。我想念什么?
public void onClick(View v) {
URI website = null;
HttpResponse response = null;
BufferedReader in = null;
InputStream is = null;
String result = "hello";
JSONObject jArray = null;
HttpClient client = new DefaultHttpClient();
try {
website = new URI("http://fakesite.com");
} catch (URISyntaxException e) {
e.printStackTrace();
}
HttpGet getRequest = new HttpGet();
getRequest.setURI(website);
HttpPost postRequest = new HttpPost(website);
try {
List<NameValuePair> nameValuePairs = new ArrayList<NameValuePair>(2);
nameValuePairs.add(new BasicNameValuePair("name", name.toString() ));
postRequest.setEntity(new UrlEncodedFormEntity(nameValuePairs));
response = client.execute(postRequest);
HttpEntity entity = response.getEntity();
is = entity.getContent();
results.append(" got response");
} catch (ClientProtocolException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
}
try {
BufferedReader reader = new BufferedReader(new InputStreamReader(is,"iso-8859-1"),8);
StringBuilder sb = new StringBuilder();
String line = null;
while ((line = reader.readLine()) != null) {
sb.append(line + "\n");
}
is.close();
result=sb.toString();
results.append(result);
} catch (UnsupportedEncodingException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
}
}