我如何从Android手机获得网站价值

时间:2013-05-10 04:21:26

标签: android web

我将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方面遇到任何错误。如何检索上述网站中的值

2 个答案:

答案 0 :(得分:1)

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

这就是你可以从该脚本中的帖子请求中检索数据的方式..

答案 1 :(得分: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
 }
 }