从HTTPURLConnection读取大数字响应为String

时间:2016-06-12 20:16:58

标签: android httpurlconnection atg

需要Httpurlconnection android响应帮助作为字符串, 我正在与ATG Portal合作,在这里我面临着关于JSON响应的大问题。

ATG REST API将返回一个会话确认号,这个号码的大小很大而Long不能保存它的值,当它收到时,号码会变圆。

  

有没有办法使用HttpURLconnection以字符串形式接收响应?

这是正在运行的代码

 String url = "http://IP:Port/rest/model/atg/rest/SessionConfirmationActor/getSessionConfirmationNumber";
        HttpURLConnection httpcon;
        StringBuilder response  = new StringBuilder();
        try {
            //Connect
            httpcon = (HttpURLConnection) ((new URL(url).openConnection()));
            httpcon.setRequestMethod("GET");
            httpcon.setReadTimeout(10000); // millis
            httpcon.setConnectTimeout(15000); // millis
            httpcon.setRequestProperty("Connection", "Keep-Alive");
            httpcon.setRequestProperty("Content-Type", "application/xml; charset=utf-8");
            httpcon.setRequestProperty("charset", "utf-8");
            httpcon.setRequestProperty("Expect", "100-continue");
            httpcon.setDoOutput(true);
            httpcon.connect();
            if (httpcon.getResponseCode() == HttpURLConnection.HTTP_OK)
            {
                InputStream stream = httpcon.getInputStream();
                InputStreamReader isReader = new InputStreamReader(stream );
                BufferedReader input = new BufferedReader(isReader );
                String strLine = null;
                while ((strLine = input.readLine()) != null)
                {
                    response.append(strLine);
                    Log.v("-------------------------------LoginActivity", String.valueOf(response));
                }
                input.close();
            }
            JSONObject obj = new JSONObject(String.valueOf(response));
            String date = obj.getString("sessionConfirmationNumber");
            httpcon.disconnect();
            Log.v("-------------------------------LoginActivity", date);

        }catch (UnsupportedEncodingException e) {
            e.printStackTrace();
        } catch (IOException e) {
            e.printStackTrace();
        } catch (JSONException e) {
            e.printStackTrace();
        }
        return "Hello";
    }

我遇到了与webPortal相同的问题,我已经解决了使用XMLhttpconnection方法请帮助.....!

0 个答案:

没有答案