尝试使用 HTTP POST 请求更新数据库参数时,我得到以下结果:
Exception in thread "main" java.io.IOException: Server returned HTTP response code: 405 for URL:
at sun.net.www.protocol.http.HttpURLConnection.getInputStream0(HttpURLConnection.java:1840)
at sun.net.www.protocol.http.HttpURLConnection.getInputStream(HttpURLConnection.java:1441)
at istsos.IstSOS.ExecuteRequest(IstSOS.java:210)
at istsos.Database.setDatabase(Database.java:77)
at istsos.Database.main(Database.java:105)
我删除了网址。
无论如何,我检查了 REST 响应,它在应用程序中工作正常。
在 IstSOS 类中,ExecuteRequest 方法似乎在获取响应时存在问题:
httpCon.setDoOutput(true);
httpCon.setRequestMethod(httpMethod);
DataOutputStream wr = new DataOutputStream(httpCon.getOutputStream());
wr.write(postDataBytes);
wr.flush();
wr.close();
BufferedReader in = new BufferedReader(new InputStreamReader(httpCon.getInputStream()));
//assigning response to JSON
String inputLine;
JSONObject jsonResponse = new JSONObject();
while((inputLine = in.readLine()) != null)
//System.out.println(inputLine);
jsonResponse = new JSONObject(inputLine);
基本上最后,我将在 Java 库中使用 JSON 返回一个 JSONObject 来解析响应。
到目前为止,我已经尝试使用try/catch和System.out.print来查看出了什么问题,但这次我无法真正看到发生了什么。
此外,这种请求是可能的,据我所知,服务器不会限制它。
最后,我解决了这个问题。很明显,很明显,我无法通过这种方法更新数据库......