简体   繁体   中英

PATCH request using HttpURLConnection in JAVA

How to execute PATCH request of RESTHeart API using HttpURLConnection in JAVA .Its giving back 405 as status.

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());
}
}

Http code 405 means method not allowed. This indicates that your web server is not allowing PATCH requests and that you'll need to configure it to accept PATCH method type.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM