lundi 15 juin 2015

HTTP GET request get HTML page code instead of expected json Response

/Here is the code/ http://ift.tt/1Gnzw0c"> HTTP/1.1 400 Bad Request Server: PipeGuard Date: Mon, 15 Jun 2015 10:29:32 GMT Content-Type: text/html Content-Length: 605 Connection: close

<!DOCTYPE HTML PUBLIC "-//IETF//DTD HTML 2.0//EN">
<html>
<head><title>400 Bad Request</title></head>
<body bgcolor="white">
<h1>400 Bad Request</h1>
<p>Your browser sent a request that this server could not understand. Sorry for the inconvenience.<br/>
    Please report this message and include the following information to us.<br/>
    Thank you very much!</p>
<table>
    <tr>
        <td>URL:</td>
        <td>http://_</td>
    </tr>
    <tr>
        <td>Server:</td>
        <td>5.254.102.236.r00t-services.net</td>
    </tr>
    <tr>
        <td>Date:</td>
        <td>2015/06/15 10:29:32</td>
    </tr>
</table>
<hr/>Powered by PipeGuard</body>
</html>

Here is my call

URL url = new URL("http://ift.tt/1Gnzw0c"); String query = "api_key=q5EicSKs027cjut7qhZk&method";

            //make connection
            URLConnection urlc = url.openConnection();

            //use post mode
            urlc.setDoOutput(true);
            urlc.setAllowUserInteraction(false);

            //send query
            PrintStream ps = new PrintStream(urlc.getOutputStream());
            ps.print(query);
            ps.close();

            //get result
            BufferedReader br = new BufferedReader(new InputStreamReader(urlc
                .getInputStream()));
            String l = null;
            while ((l=br.readLine())!=null) {
                System.out.println(l);
            }
            br.close();

Aucun commentaire:

Enregistrer un commentaire