This post request goes to a php page that connects to my database that queries whatever is in the textfield “name”. The string that is appended to results is always null when I know for a fact they are not null. What am I miss?
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();
}
}
nameValuePairs.add(new BasicNameValuePair(“name”, name.toString() ));
what is name in name.toString(). Where are you initialising the name object?