Uploaded image for project: 'JDK'
  1. JDK
  2. JDK-8207840

HTTPUrlConnection does not accept PATCH method

XMLWordPrintable

      A DESCRIPTION OF THE PROBLEM :
      For the moment, it is impossible to make an HTTP PATCH request with HttpURLConnection object. PATCH is a valid HTTP Verb and is described on RFC 5789.

      HTTP PATCH method RFC: https://tools.ietf.org/html/rfc5789

      STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
      Use this main :

      public static void main(String[] args) throws IOException {
          HttpURLConnection httpURLConnection = (HttpURLConnection) new URL("https://httpbin.org/patch").openConnection();
          httpURLConnection.setRequestMethod("PATCH");
          System.out.println(httpURLConnection.getResponseCode());
      }

      ACTUAL -
      Exception in thread "main" java.net.ProtocolException: Invalid HTTP method: PATCH

      ---------- BEGIN SOURCE ----------
      HttpURLConnection httpURLConnection = (HttpURLConnection) new URL("https://httpbin.org/patch").openConnection();
      httpURLConnection.setRequestMethod("PATCH");
      assertEquals(200, httpURLConnection.getResponseCode());
      ---------- END SOURCE ----------

      CUSTOMER SUBMITTED WORKAROUND :
      It's possible to bypass this bug by using reflection: rewrite the HttpUrlConnections.methods field to add the "PATCH" string into the array.

      FREQUENCY : always


            chegar Chris Hegarty
            webbuggrp Webbug Group
            Votes:
            0 Vote for this issue
            Watchers:
            3 Start watching this issue

              Created:
              Updated:
              Resolved: