0

I have curl command:

curl -k -f  --header "Authorization: bearer cb084803-xxxx-xxxx-xxxx-2a275e112c38 " 
--header "Content-Type:multipart/form-data" 
--header "X-PartnerUserId:login01" 
--form "title=fileName" 
--form "tag=mytag" 
--form "archive=@test.pdf;type=application/pdf" 
-X POST https://api.EXAMPLEAPI.com/api/v2.0/doc

And I want to create HTTP Request in Java API which will do the same thing But i don't know how can'i do for the param (--form ....)

    Map<String, String> mapResponse = new HashMap<String, String>();
    String resourceURL = config.getProperty(OAuthConstants.RESOURCE_SERVER_URL_UPLOAD);
    OAuth2Details oauthDetails = createOAuthDetails(config);

    HttpPost httpPost = new HttpPost(resourceURL);
    httpPost.setHeader(OAuthConstants.AUTHORIZATION, getAuthorizationHeaderForAccessToken(oauthDetails.getAccessToken()));
    httpPost.setHeader(OAuthConstants.CONTENTE_TYPE, OAuthConstants.ENCODED_CONTENT_DATA);
    httpPost.setHeader(OAuthConstants.PARTNERUSERID, login);
    //------------------------------------------------------------------------
    httpPost.set...  // add: --form "title=fileName" 
    httpPost.set...  // add: --form "tag=mytag" 
    httpPost.set...  // add: --form "archive=@test.pdf;type=application/pdf" 
    //------------------------------------------------------------------------
    DefaultHttpClient httpClient = new DefaultHttpClient();
    HttpResponse response = null;
    int code = -1;
    try {
        response = httpClient.execute(httpPost);
        code = response.getStatusLine().getStatusCode();

Any help appreciated.

Yanni
  • 103
  • 3
  • 14
  • http://stackoverflow.com/questions/2304663/apache-httpclient-making-multipart-form-post – Brett Okken Jun 23 '14 at 12:18
  • thanks Brett. but this solution does not working for me – Yanni Jun 23 '14 at 12:27
  • Http error: 500 Internal error od Servlet I do like this: List parameters = new ArrayList(); parameters.add(new BasicNameValuePair(OAuthConstants.PARTNERUSERID, doc.getTitre())); httpPost.setEntity(new UrlEncodedFormEntity(parameters)); – Yanni Jun 23 '14 at 12:50
  • Please show your updated code. Also provide the failure from the server if available. – Brett Okken Jun 23 '14 at 12:51

0 Answers0