0

" " でアプリがクラッシュし((HttpResponse) httpGet).setEntity(new StringEntity(jo.toString(),"UTF-8"));、例外 " " がスローされjava.lang.ClassCastException:org.apache.http.client.methods.HttpGetます。

JSONObject jo = new JSONObject();
    try {
        jo.put("devicetoken", devicetoken);
        URI uri = new URI("http", "praylistws-dev.elasticbeanstalk.com",
                "/rest/list/myprayerlist/"+Helper.email, null, null);

        HttpClient httpClient = new DefaultHttpClient();
        HttpGet httpGet = new HttpGet(uri);

        // Prepare JSON to send by setting the entity
        ((HttpResponse) httpGet).setEntity(new StringEntity(jo.toString(),
                "UTF-8"));

        // Set up the header types needed to properly transfer JSON
        httpGet.setHeader("Content-Type", "application/json");
        httpGet.setHeader("Accept-Encoding", "application/json");
        httpGet.setHeader("Accept-Language", "en-US");

        // Execute POST
        response = httpClient.execute(httpGet);
        String string_response = EntityUtils.toString(response.getEntity());
        string_resp = string_response += "";
    } catch (Exception ex) {
        ex.printStackTrace();
    }
    save(string_resp);
    return result;
4

2 に答える 2

0

Activity{ oncreate{ new HitService().execute(addparams here); } }

protected String doInBackground(String... params) {

                String result = null;

                HttpClient httpClient = new DefaultHttpClient();
                HttpGet httpGet = new HttpGet("http://your url=" + params[0]);


                HttpResponse response;
                try { 
                        response = httpClient.execute(httpGet);                
                        result = EntityUtils.toString(response.getEntity());         

                } catch (ClientProtocolException e) {

                        e.printStackTrace();
                } catch (IOException e) {

                        e.printStackTrace();
                }

                return result;
        }
于 2013-09-19T11:06:09.150 に答える