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

Missing content-type MultipartEntity Request

    XMLWordPrintableJSON

Details

    • Bug
    • Status: Closed
    • Blocker
    • Resolution: Invalid
    • 4.2.3
    • None
    • HttpClient (classic)
    • OS: Windows 7 (Microsoft Windows [Version 6.1.7600])
      JDK: jdk1.7.0_13

      Libs:
      - httpclient-4.2.3.jar
      - httpcore-4.2.2.jar
      - httpmime-4.2.3.jar

    Description

          • Given the following code:

      HttpClient httpClient = new DefaultHttpClient();
      MultipartEntity entity = new MultipartEntity(HttpMultipartMode.BROWSER_COMPATIBLE);
      entity.addPart("metadata", new StringBody("

      { \"number\": 4}

      ", "application/json", Charset.forName("UTF-8")));
      HttpPost httpPost = new HttpPost("http://localhost:8080/");
      httpPost.setEntity(entity);
      httpClient.execute(httpPost);

          • The request comes out without the requested content-type ("application/json") and cannot be interpreted by the application server. There should be a "Content-Type: application/json" right after Content-Disposition in the request body below.

      POST /boards/publish/123/images/an_image_field_key
      Host: localhost:8080
      Content-type: multipart/form-data; boundary=hRc10UDcwcHyZlNbQwa2NaN-Qq4FxhIq3VHUoKk0
      Content-length: 282
      Connection: Keep-Alive
      User-agent: Apache-HttpClient/4.2.3 (java 1.5)

      --hRc10UDcwcHyZlNbQwa2NaN-Qq4FxhIq3VHUoKk0
      Content-Disposition: form-data; name="metadata"

      { "number": 4}

      -hRc10UDcwcHyZlNbQwa2NaN-Qq4FxhIq3VHUoKk0-

      Attachments

        Activity

          People

            Unassigned Unassigned
            victorclf Victor Freire
            Votes:
            0 Vote for this issue
            Watchers:
            2 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved: