Reputation: 11
i am trying to post and receive data from a php file. but i am not able to do it. this is my code for posting and receiving data into a php file
public void submit(){
String result = null;
InputStream is = null;
StringBuilder sb=null;
ArrayList<NameValuePair> nameValuePairs = new ArrayList<NameValuePair>(1);
nameValuePairs.add(new BasicNameValuePair("registerno",registerno));
try{
HttpClient httpclient = new DefaultHttpClient();
HttpPost httppost = new HttpPost("http://serveraddress/a.php");
httppost.setEntity(new UrlEncodedFormEntity(nameValuePairs));
HttpResponse response = httpclient.execute(httppost);
HttpEntity entity = response.getEntity();
is = entity.getContent();
}
catch(Exception e){
Log.e("log_tag", "Error in http connection"+e.toString());
} //convert response to string
try{
BufferedReader reader = new BufferedReader(new InputStreamReader(is,"iso-8859-1"),80);
sb = new StringBuilder();
sb.append(reader.readLine() + "\n");
String line="0";
while ((line = reader.readLine()) != null)
{
sb.append(line + "\n"); }
is.close();
result=sb.toString();
Toast.makeText(getBaseContext(),result.toString(), Toast.LENGTH_LONG).show();
}
catch(Exception e){
Log.e("log_tag", "Error converting result "+e.toString());
}
and this is my php file a.php
<?php
$reg=$_POST['registerno'];
print(json_encode($reg));
?>
i am getting output as
"android.widget.EditText@45f6567d8"
can anyone help me out for this
Upvotes: 0
Views: 52
Reputation: 14199
use toString() when getting value from EditText
something like : getText().toString();
Upvotes: 1