-2

我正在做一个android应用程序,我只是做了一个get http请求,我只想知道我做错了什么。

这是我的要求:

try {
    String encodedUserNAme = idDispositivo;
    encodedUserNAme =  URLEncoder.encode(encodedUserNAme, "utf-8");
    String url = Constants.URL_OBTENER_GRUPO + "?" + "user="+ idDispositivo;
    Log.w("ObtenerIDGrupo "," url: "+url);



    HttpClient client = Constants.getHttpClient();
    HttpGet httpget;
    try {
        httpget = new HttpGet(new URI(url));

        try{
            HttpResponse response = client.execute(httpget);
            String responseBody = EntityUtils.toString(response.getEntity());

                    Log.w("ObtenerIDGrupo "," RESPONSEBODY= "+responseBody);
                    idGrupo = responseBody;
                    Log.w("ObtenerIDGrupo "," idGrupo= "+responseBody);

        }catch(ClientProtocolException e){
            e.printStackTrace();
        }catch(IOException e){
            e.printStackTrace();
        }
    } catch (URISyntaxException e1) {
        e1.printStackTrace();
    }
} catch (IOException e) {
    Log.w("IOException" + e);
    e.printStackTrace();
}

这是我的回应:

在此处输入图像描述

我不知道为什么会有这样的反应。有人能帮助我吗?

谢谢

4

2 回答 2

1

您不能像这样操纵响应,请尝试以下代码:

InputStream is = response.getEntity().getContent();        
BufferedReader bufferedReader = new BufferedReader(
            new InputStreamReader(is));

StringBuilder str = new StringBuilder();
String line = null;

while ((line = bufferedReader.readLine()) != null) {
    str.append(line + "\n");
}
responseBody = str.toString();
Log.w("ObtenerIDGrupo "," RESPONSEBODY= "+responseBody);
于 2013-02-26T10:17:37.383 回答
0

试试这个

  URL url = new URL(yoururl);
         InputStream input=url.openStream();
         BufferedInputStream bis=new BufferedInputStream(input);
         ByteArrayBuffer baf=new ByteArrayBuffer(1000);
         while((k=bis.read())!=-1)
         {
         baf.append((byte)k);
         }
        String responsedata=new String(baf.toByteArray());
于 2013-02-26T10:21:14.513 回答