如何将curl调用转换为java HttpPostcall

如何将curl调用转换为java HttpPostcall,java,curl,http-headers,Java,Curl,Http Headers,我有一个命令: 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=a

我有一个命令:

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
我想在JavaAPI中创建HTTP请求,它也会做同样的事情 但我不知道我该如何处理参数(--form…)

MapMapResponse=newHashMap();
字符串resourceURL=config.getProperty(OAuthConstants.RESOURCE\u服务器\u URL\u上传);
OAuth2Details oauthDetails=createOAuthDetails(配置);
HttpPost HttpPost=新的HttpPost(资源URL);
setHeader(OAuthConstants.AUTHORIZATION,getAuthorizationHeaderForAccessToken(oauthDetails.getAccessToken());
setHeader(OAuthConstants.CONTENTE_类型,OAuthConstants.ENCODED_内容_数据);
setHeader(OAuthConstants.PARTNERUSERID,登录名);
//------------------------------------------------------------------------
httpPost.set…//添加:--格式“title=fileName”
httpPost.set…//添加:--格式“tag=mytag”
httpPost.set…//添加:--form“archive=@test.pdf;type=application/pdf”
//------------------------------------------------------------------------
DefaultHttpClient httpClient=新的DefaultHttpClient();
HttpResponse响应=null;
int代码=-1;
试一试{
response=httpClient.execute(httpPost);
代码=响应。getStatusLine().getStatusCode();

非常感谢您的帮助。

谢谢Brett。但是此解决方案不适用于meHttp错误:500内部错误od Servlet我喜欢这样:列出参数=新ArrayList();参数。添加(新的BasicNameValuePair(OAuthConstants.PARTNERUSERID,doc.getTitre());httpPost.setEntity(新的UrlEncodedFormEntity(参数));请显示更新后的代码。如果可用,请提供服务器的故障信息。
    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();