Http Get Request returns html?

I am using http get Request to load data in android. I don't know that it returns html instead of the JSON result. The same url gets json when loading in the browser, but in response to the incoming html.

my Http Get call format Like this ...

url = new URL(urlString);

        //httpURLConnection = (HttpsURLConnection) url.openConnection();
        httpURLConnection = (HttpURLConnection) url.openConnection();

        httpURLConnection.setRequestMethod("GET");
        httpURLConnection.setRequestProperty("Connection", "keep-alive");

        httpURLConnection.setRequestProperty("Accept", "application/json"); // or application/jsonrequest
        httpURLConnection.setRequestProperty("Content-Type", "application/json");
        /*
        httpURLConnection.setRequestProperty("Content-Type",
                "application/json");*/
        httpURLConnection.setRequestProperty("UseCookieContainer", "True");
        httpURLConnection.setRequestProperty("Cookie", cokieValue);
        httpURLConnection.connect();
+4
source share
3 answers

After checking the code on the server side. after the onset means changing a code like this ...

url = new URL(urlString);

        httpURLConnection = (HttpsURLConnection) url.openConnection();
        //httpURLConnection = (HttpURLConnection) url.openConnection();
    //  HttpsURLConnection.setDefaultHostnameVerifier(new NullHostNameVerifier());
        httpURLConnection.setRequestMethod("GET");
        httpURLConnection.setRequestProperty("Connection", "keep-alive");
        httpURLConnection.setRequestProperty("Content-Type",
                "application/json");
        httpURLConnection.setRequestProperty("UseCookieContainer", "True");
        httpURLConnection.setChunkedStreamingMode(0);
        httpURLConnection.connect();

        if (httpURLConnection != null) {
            respCode = httpURLConnection.getResponseCode();
            messageStatus.setResponseCode(respCode);
        }
        if (respCode == 200) {
            InputStream responseStream = httpURLConnection.getInputStream();
            messageStatus.setResponseStream(responseStream);
        }
+1
source

Do you control the targeted web service?

You tried using "text / x-json" as the content type. Recently it turned out that some systems do not support application / json, even if it is a standard.

+1

JSON, . PHP, :

print(json_encode($response));

. ​​

+1

Source: https://habr.com/ru/post/1568878/


All Articles