0
如何使用JAVA中的HttpURLConnection執行RESTHeart API的PATCH請求。它將405返回爲狀態。在JAVA中使用HttpURLConnection的PATCH請求
public class TestRestHeartUpdate{
public static void main(String[] args) throws Exception{
URL url;
url = new
URL("http://127.0.0.1:8080/testDB1/col1/5967c13e61f73b88018db783");
HttpURLConnection hc;
hc = (HttpURLConnection) url.openConnection();
hc.setDoInput(true);
hc.setDoOutput(true);
hc.setRequestMethod("POST");
hc.setRequestProperty("X-HTTP-Method-Override", "PATCH");
hc.setRequestProperty("Content-Type","application/hal+json");
hc.setRequestProperty("Accept","application/hal+json");
hc.setInstanceFollowRedirects(false);
hc.setRequestProperty("If-Match","5967c28f42483b1c3dbedc54");
hc.setUseCaches(false);
hc.connect();
byte[] opB = " {'rating':'VeryGood'}".getBytes("UTF-8");
OutputStream os = hc.getOutputStream();
os.write(opB);
System.out.println(hc.getResponseCode());
}
}
你能告訴我如何配置服務器接受PATCH方法類型 –