apache commons httpclient - Unable to POST data using TLS 1.2 -
i trying post data server using tls1.2 when running code getting following response server.
httpresponseproxy{http/1.1 415 unsupported media type [date: wed, 07 sep 2016 17:42:57 cst, server: , strict-transport-security: max-age=63072000; includesubdomains; preload, pragma: no-cache, content-length: 0, charset: iso-8859-1, x-oracle-dms-rid: 0, x-oracle-dms-ecid: 343fa6c0-ed24-4003-ad58-342caf000404-00000383, set-cookie: jsessionid=1zmivt1nqrtwphghs4mmmyytpugtoqgra9bice3dok5v0gdcpxu6!681252631; path=/; secure; httponly;httponly;secure, cache-control: no-store, p3p: policyref="/w3c/p3p.xml", cp="wbp dsp nor amt adm dot urt pot not", keep-alive: timeout=5, max=250, connection: keep-alive, content-type: text/xml, content-language: en] [content-type: text/xml,content-length: 0,chunked: false]}
i using below code post data server . using apache httpcomponents-client-4.5.2.
private static registry<connectionsocketfactory> getregistry() throws keymanagementexception, nosuchalgorithmexception { sslcontext sslcontext = sslcontexts.custom().build(); sslconnectionsocketfactory sslconnectionsocketfactory = new sslconnectionsocketfactory(sslcontext, new string[]{"tlsv1.2"}, null, sslconnectionsocketfactory.getdefaulthostnameverifier()); return registrybuilder.<connectionsocketfactory>create() .register("https", sslconnectionsocketfactory) .register("https", sslconnectionsocketfactory) .build(); } public static void main(string[] args) throws exception { poolinghttpclientconnectionmanager clientconnectionmanager = new poolinghttpclientconnectionmanager(getregistry()); clientconnectionmanager.setmaxtotal(100); clientconnectionmanager.setdefaultmaxperroute(20); httpclient client = httpclients.custom().setconnectionmanager(clientconnectionmanager).build(); httppost request = new httppost("https://someserver.com/dataupload"); file file = new file("c://nible//code//_client//request.xml"); multipartentitybuilder builder = multipartentitybuilder.create(); builder.setmode(httpmultipartmode.browser_compatible); builder.setcontenttype(contenttype.text_xml); filebody filebody = new filebody(file); builder.addpart("my_file", filebody); httpentity reqentity = builder.build(); request.setentity(reqentity); httpresponse response = client.execute(request); system.out.println(response); }
can please tell me wrong doing?
i tried using below code instead of multipartentitybuilder. still getting same error.
entitybuilder builder = entitybuilder.create(); builder.setfile(file); builder.setcontenttype(contenttype.text_xml);
if sending blank request server getting same error. blank error means not putting thing in request
httppost request = new httppost("https://someserver.com/dataupload"); httpresponse response = client.execute(request);
i suspect of these lines in code:
multipartentitybuilder builder = multipartentitybuilder.create(); builder.setmode(httpmultipartmode.browser_compatible); builder.setcontenttype(contenttype.text_xml);
multipart entities cannot of content-type xml. must 1 of these types:
- multipart/mixed
- multipart/alternative
- multipart/digest
- multipart/parallel
(see rfc 1341 7.2)
i guess should use 1 of these content-types multipart entity, , set text/xml
content type of single part:
filebody filebody = new filebody(file, contenttype.text_xml);
(another issue don't see necessary send multipart 1 file: leave out multipartentitybuilder
object , build directly fileentity.)
Comments
Post a Comment