2011-08-06 26 views
-1

私のウェブとアンドロイド間の通信を試みています。私のアンドロイドからPHPページにデータを送信するのが難しく、JSONを使って通信しています。私に助けてください........アンドロイドでJSONを使用してデータをPHPページに送信する方法

+0

次のリンクを経由してください。http://stackoverflow.com/questions/3027066/how-to-send-a- json-object-over-request-with-android – Basil

答えて

1

あなたのデバイスからPHPページに実際にPOST要求をしないのはなぜですか?結局のところ、PHPはリクエストを処理する上で本当にうまく機能しているので、実際には問題ではありません。これを試してみてください:

Java:

// Create a new HttpClient and Post Header 
HttpClient httpclient = new DefaultHttpClient(); 
HttpPost httppost = new HttpPost("http://yoursite.com"); 

try { 
    // Add your data 
    List<BasicNameValuePair> nameValuePairs = new ArrayList<BasicNameValuePair>(2); 
nameValuePairs.add(new BasicNameValuePair("string1", "foo")); 
nameValuePairs.add(new BasicNameValuePair("string2", "bar")); 
httppost.setEntity(new UrlEncodedFormEntity(nameValuePairs)); 

//Execute HTTP Post Request 
HttpResponse response = httpclient.execute(httppost); 

    //Check the response 
    if(response == null) return null; 

    //POST DONE 

} catch(Exception ex) { 

    ex.printStackTrace(); 

} 

php:

<?php 
    if(isset($_POST['string1'])) { 

     //Do stuff with the $_POST 

    } else { 

     //Nothing to see here 

    } 
?> 
関連する問題