1

I'm trying to read the json response of a request post. This is the code ...

        connection.getOutputStream().write(paramDataBytes);
        Reader in = new BufferedReader(new InputStreamReader (connection.getInputStream(),"UTF-8"));
        StringBuilder sb = new StringBuilder();
        for(int c;(c=in.read())>=0;)
            sb.append((char)c);
        String response = sb.toString();
        System.out.println(response);
        JSONObject myResponse = new JSONObject(response.toString());

but the of response variable is

"?; ?m???×"}?iU?(s? ?0?p?6]p????E??*?Q????*U@?g?-x??1D@ ?H??P?{?a?P??w?KV?"

why?

when I try to create the object "JSONObject myResponse " I have the following error

Exception in thread "main" org.json.JSONException: A JSONObject text must begin with '{' at 1 [character 2 line 1]
    at org.json.JSONTokener.syntaxError(JSONTokener.java:505)
    at org.json.JSONObject.<init>(JSONObject.java:215)
    at org.json.JSONObject.<init>(JSONObject.java:399)
    at com.application.HttpRequestRaffle.main.Main2.main(Main2.java:83)

I desperately need help...

this is the response of the request that I do manually through firefox

enter image description here

xxxvodnikxxx
  • 1,270
  • 2
  • 18
  • 37
Frato
  • 25
  • 5
  • 2
    Are you sure the called URL returns valid json output? Maybe the error is not on your side.. I have also found [this example](https://stackoverflow.com/questions/4308554/simplest-way-to-read-json-from-a-url-in-java) of calling an URL to get json response, it uses json parser, but if you will get an text as you mentioned, then it will not be working for sure – xxxvodnikxxx Jun 14 '18 at 10:30
  • 2
    in the image I have inserted there is the response – Frato Jun 14 '18 at 10:53
  • 1
    i have resolve, the response was compressed. – Frato Jun 29 '18 at 09:12
  • Hi, thanks for followup and feedback, if possible please put it as a answer and once it will be possible accept it by your own. That will help for proper post filtering, etc.. – xxxvodnikxxx Jun 29 '18 at 09:38

2 Answers2

1

i have resolve, the response was compressed.

Frato
  • 25
  • 5
0

-- as you can see in comments Its resolved,

@Frato: "i have resolve, the response was compressed. – Frato"

Putting separate answer post to prevent new answers

xxxvodnikxxx
  • 1,270
  • 2
  • 18
  • 37