0

我正在尝试从 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"

谁能帮我解决这个问题

4

1 回答 1

1

从以下内容获取价值时使用toString()EditTextgetText().toString();

于 2013-07-14T16:59:12.917 回答