gpt4 book ai didi

Java http 调用返回响应代码 : 501

转载 作者:行者123 更新时间:2023-12-01 19:25:28 25 4
gpt4 key购买 nike

我遇到此错误:

**Server returned HTTP response code: 501 for URL: http://dev1:8080/data/xml/01423_01.xml**      

查看这段代码:

   private static Map sendRequest(String hostName, String serviceName) throws Exception {
Map assets = null;
HttpURLConnection connection = null;

Authenticator.setDefault(new Authenticator());


URL serviceURL = new URL(hostName + "/" + serviceName);
connection = (HttpURLConnection)serviceURL.openConnection();
connection.setRequestMethod("GET");
ClientHttpRequest postRequest = new ClientHttpRequest(connection);

InputStream input = null;


/*

At line input = postRequest.post(); I get the following error
Server returned HTTP response code: 501 for URL: http://dev1:8080/data/xml/01423_01.xml

Yet if I enter that url in my browser it opens up fine.
Is this a common problem? Is there some type of content type I need to set?
*/
input = postRequest.post();
connection.disconnect();
return assets;
}

最佳答案

501 响应意味着“未实现”,通常意味着服务器不理解您使用的 HTTP 方法(例如 get、post 等)。

我不认识 ClientHttpRequest ,但你有一行内容

connection.setRequestMethod("GET");

然后一行写着

input = postRequest.post();

我不确定 post() 实际上做了什么,但这是否意味着发送 POST 请求?如果是这样,则与第一行中指定的 GET 相矛盾。

无论哪种方式,服务器都会说它不在 GET 或 POST 方法下,无论您的代码实际发送的是哪一种。您需要找出服务器支持该 URL 的方法,然后使用它。

关于Java http 调用返回响应代码 : 501,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/1406709/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com