1

我正在将价值从 android 手机发送到网站。该网站通过一些免费资源在线注册。

代码是,

public class HttpStorage extends AsyncTask{
   protected void onPreExecute() {
        super.onPreExecute();
   }
   protected void onPostExecute(Integer result) {
   }

public void postData() {
    HttpClient httpclient = new DefaultHttpClient();
    HttpPost httppost = new      
    HttpPost("http://pavithrakrishnakumar.simplesite.com/");

    try {
        List <NameValuePair> nameValuePairs = new ArrayList<NameValuePair>();
        nameValuePairs.add(new BasicNameValuePair("IDToken1", "username"));
        nameValuePairs.add(new BasicNameValuePair("IDToken2", "password"));
        httppost.setEntity(new UrlEncodedFormEntity(nameValuePairs));
        HttpResponse response = httpclient.execute(httppost);
    } catch (ClientProtocolException e) {
    } catch (IOException e) {
    }
}

@Override
protected Object doInBackground(Object... arg0) {
        postData();
    return null;
}
}

现在我在 android 端没有收到任何错误。如何检索上述站点中的值

4

2 回答 2

1
<?php
    $IDToken1 = $_POST['IDToken1'];
    $IDToken2 = $_POST['IDToken2'];

这就是您可以从该脚本中的发布请求中检索数据的方式..

于 2013-05-10T04:26:28.497 回答
0
        public void postData() {
    // Create a new HttpClient and Post Header
    HttpClient httpclient = new DefaultHttpClient();
    HttpPost httppost = new      
    HttpPost("http://pavithrakrishnakumar.simplesite.com/");

    try {
         List <NameValuePair> nameValuePairs = new ArrayList<NameValuePair>();
        nameValuePairs.add(new BasicNameValuePair("IDToken1", "username"));
        nameValuePairs.add(new BasicNameValuePair("IDToken2", "password"));


        httppost.setEntity(new UrlEncodedFormEntity(nameValuePairs));

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

        if(response != null) {

          int statuscode = response.getStatusLine().getStatusCode();

           if(statuscode==HttpStatus.SC_OK) {
            String strResponse = EntityUtils.toString(response.getEntity());

          }
       }

 } catch (ClientProtocolException e) {
   // TODO Auto-generated catch block
 } catch (IOException e) {
        // TODO Auto-generated catch block
 }
 }
于 2013-05-10T04:48:06.940 回答