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 に答える