Saturday, 15 February 2014

java - How represente the curl command using the HttpPost: curl --form "tag=mytag" --form "archive=@test.pdf;type=application/pdf" -



java - How represente the curl command using the HttpPost: curl --form "tag=mytag" --form "archive=@test.pdf;type=application/pdf" -

how represente curl command using httppost:

curl --form "tag=mytag" --form "archive=@c:/etc/test.pdf;type=application/pdf" ...

below code:

httppost httppost = new httppost(www.resourceurl.com); httppost.setheader(authorization: bearer cb084803-ba48-xxxx-xxxx-2a275e199c38) ....

below code i've done: receive http 500 error

list<namevaluepair> parameters = new arraylist<namevaluepair>(); httppost httppost = new httppost(resourceurl); httppost.setheader(oauthconstants.authorization, bearer cb084803-ba48-xxx-xxx-2a275xxx99c38 )); httppost.setheader(oauthconstants.contente_type, oauthconstants.encoded_content_data); httppost.setheader(oauthconstants.partneruserid, login); //------------------------------------------------------------------------ parameters.add(new basicnamevaluepair("title", doc.gettitre())); parameters.add(new basicnamevaluepair("tag", doc.gettag())); parameters.add(new basicnamevaluepair("archive", "@" + doc.getpath() + ";type=application/pdf")); httppost.setentity(new urlencodedformentity(parameters)); //------------------------------------------------------------------------ defaulthttpclient httpclient = new defaulthttpclient(); httpresponse response = null; response = httpclient.execute(httppost); code = response.getstatusline().getstatuscode();

i not know how solve problem

i check content contenet of response , have result:

[{"error":"bad_request","error_description":"malformed json : expected begin_object string @ line 1 column 1"}]

create urlencodedformentity , add together form elements there

list<namevaluepair> formentries = new arraylist<>(); // or whatever list sub-type formentries.add(new basicnamevaluepair("tag", "my-tag")); // more urlencodedformentity entity = new urlencodedformentity(formentries); httppost.setentity(entity);

java json http curl http-post

No comments:

Post a Comment