【问题标题】:Exception in thread "main" java.io.IOException: Server returned HTTP response code: 405线程“main”java.io.IOException 中的异常:服务器返回 HTTP 响应代码:405
【发布时间】:2021-01-06 06:58:46
【问题描述】:
ULR url = new URL(urlString);

HttpURLConnection con = (HttpURLConnection) url.openConnection();

con.setRequestMethod("GET");

con.connect();

BufferedReader in = new BufferedReader(new InputStreamReader(con.getInputStream())); 

String inputLine;

StringBuffer response = new StringBuffer();

while ((inputLine = in.readLine()) != null) 

{

response.append(inputLine);

}

in.close();

System.out.println(response.toString());

【问题讨论】:

  • 405 状态码表示该请求方法不允许用于特定资源。更多详情请参考developer.mozilla.org/en-US/docs/Web/HTTP/Status/405
  • 欢迎来到 Stack Overflow。请阅读How to Ask。只是在这里转储代码并不是获得帮助的好方法。请提供一些关于您正在尝试执行的操作的解释以及 full 错误消息,以及行号和回溯。

标签: java get httpconnection


【解决方案1】:

请查看 HTTP 状态码:https://en.wikipedia.org/wiki/List_of_HTTP_status_codes

您的应用程序应处理所有 HTTP 标准状态代码。

【讨论】:

    猜你喜欢
    • 2013-09-12
    • 2021-07-13
    • 2013-08-12
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2023-03-18
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多