无法从php文件接收数据

时间:2013-07-14 16:56:53

标签: android

我正在尝试发布和接收来自php文件的数据。 但我无法做到。 这是我将数据发布到php文件中的代码

            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());
    } 

这是我的php文件 a.php只会

 <?php
 $reg=$_POST['registerno'];
 print(json_encode($reg));
 ?>

我的输出为

      "android.widget.EditText@45f6567d8"

任何人都可以帮助我吗

1 个答案:

答案 0 :(得分:1)

EditText获取值时,

使用 toString()getText().toString();