我在Android客户端上生成了UDID字符串。我需要将其发送到javascript端,以便它可以与数据库服务器通信(通过php)以便存储此UDID。

有没有办法直接做到这一点(避免使用php)或其他方式?

**我的Android应用程序具有WebView

最佳答案

使用参数发布到http:

public void postData() {
    // Create a new HttpClient and Post Header
    HttpClient httpclient = new DefaultHttpClient();
    HttpPost httppost = new HttpPost("http://www.yoursite.com/yourexample.php");



try {
    // Add your data
    List<NameValuePair> nameValuePairs = new ArrayList<NameValuePair>(2);
    nameValuePairs.add(new BasicNameValuePair("UDID", "12345"));
    httppost.setEntity(new UrlEncodedFormEntity(nameValuePairs));
    HttpResponse response = httpclient.execute(httppost);

} catch (ClientProtocolException e) {
    // TODO Auto-generated catch block
} catch (IOException e) {
    // TODO Auto-generated catch block
}
}


对于您的服务器端来说,了解有关Web api的知识可能会很有用。看一下这2个链接,从某个地方开始:
Creating a RESTful API with PHP
[GUIDE] Android Client-Server Communication (PHP-MYSQL REST API)

您应该显示已经完成的工作,看看this可以使问题变得更好–

10-05 20:54
查看更多