Uploaded image for project: 'HttpComponents HttpClient'
  1. HttpComponents HttpClient
  2. HTTPCLIENT-1501

Fluent API not accepting form parameters

    XMLWordPrintableJSON

Details

    • Bug
    • Status: Closed
    • Major
    • Resolution: Fixed
    • 4.3.3
    • 4.3.4, 4.4 Alpha1
    • Fluent HC
    • None

    Description

      I just tried to run the example from http://hc.apache.org/httpcomponents-client-ga/tutorial/html/fluent.html:

      Test.java
      public static void main(final String[] args) throws Exception {
      // Execute a POST with a custom header through the proxy containing a request body
      // as an HTML form and save the result to the file
      Request.Post("http://somehost/some-form")
              .addHeader("X-Custom-header", "stuff")
              .viaProxy(new HttpHost("myproxy", 8080))
              .bodyForm(Form.form().add("username", "vip").add("password", "secret").build())
              .execute().saveContent(new File("result.dump"));
      }

      and I got an unexpected error (I was expecting a connection error, but it seems that HttpClient failed before the request was sent):

      Exception in thread "main" java.lang.IllegalStateException: POST request cannot enclose an entity
      	at org.apache.http.client.fluent.Request.body(Request.java:299)
      	at org.apache.http.client.fluent.Request.bodyString(Request.java:331)
      	at org.apache.http.client.fluent.Request.bodyForm(Request.java:312)
      	at org.apache.http.client.fluent.Request.bodyForm(Request.java:316)
      

      Attachments

        Issue Links

          Activity

            People

              Unassigned Unassigned
              remisbaima Remis
              Votes:
              0 Vote for this issue
              Watchers:
              1 Start watching this issue

              Dates

                Created:
                Updated:
                Resolved: