Saturday, 15 August 2015

How convert curl call into java HttpPostcall -



How convert curl call into java HttpPostcall -

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 want create http request in java api same thing don't know how can'i 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; seek { response = httpclient.execute(httppost); code = response.getstatusline().getstatuscode();

any help appreciated.

java curl http-headers

No comments:

Post a Comment