1

AndroidフォンからWebサイトに値を送信しています。ウェブサイトは、いくつかの無料のソースを通じてオンラインで登録されています。

コードは、

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

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