Salo
Salo

Reputation: 1

Exception in thread "main" java.io.IOException: Server returned HTTP response code: 405 for URL

I use (java) HttpURLConnection to get Response from my remote server.

    URL url = new URL(URL_STRING);
    HttpURLConnection connection = (HttpURLConnection) url.openConnection();
    connection.setRequestMethod("GET");
    connection.setDoOutput(true);
    DataOutputStream out = new DataOutputStream(connection.getOutputStream());

    Map<String, String> params = new HashMap<>();
    params.put("param1", "value1");
    out.writeBytes(ParameterStringBuilder.getParamsString(params));
    out.flush();
    out.close();

    BufferedReader in = new BufferedReader(new InputStreamReader(connection.getInputStream()));
    String inputLine;
    StringBuffer content = new StringBuffer();
    while ((inputLine = in.readLine()) != null) {
        content.append(inputLine);
    }

    connection.disconnect();
    System.out.println(content);

I get this message:

Exception in thread "main" java.io.IOException: Server returned HTTP response code: 405 for URL: http://xxx

when i call the url in browser i get the answer

Upvotes: 0

Views: 38

Answers (0)

Related Questions