HTTP Post using Apache http client with expect-continue option to an authorized http proxy, and get 400 response -


i using apache http client v4.5 http post authorized required http proxy server.
because of other dependencies, tend use enabled expect-continue handshake in http client config. related code snips:

    credentialsprovider credsprovider = new basiccredentialsprovider();     credsprovider.setcredentials(             new authscope(host, port, authscope.any_realm),             new usernamepasswordcredentials(username, password));      credsprovider.setcredentials(             new authscope(proxyhost, proxyport,authscope.any_realm),             new usernamepasswordcredentials(proxyusername, proxypassword));           closeablehttpclient httpclient = httpclients.custom()             .setdefaultcredentialsprovider(credsprovider).build();      try {             httphost target = new httphost(host, port, "http");             httphost proxy = new httphost(proxyhost, proxyport);              requestconfig config = requestconfig.custom()                 .setproxy(proxy)                 .setexpectcontinueenabled(true)                 .build();              httppost httppost = new httppost("/uri");             httppost.setconfig(config);              stringentity reqentity = new stringentity(entitystring,"utf-8");             reqentity.setcontenttype("application/json");              httppost.setentity(reqentity);             closeablehttpresponse response = httpclient.execute(target, httppost);              try {                                system.out.println(response.getstatusline());                 entityutils.consume(response.getentity());             } {                  response.close();             }         } {                 httpclient.close();          } 

as target proxy server required authorization, first response proxy server 407, proxy authorization sent http client recorded in log, header "proxy-authorization" not included actual http request according wireshark capture. result, 400 bad request returned ... here apache log

http-outgoing-0 >> post http://targethost:targetport/uri/ http/1.1                             http-outgoing-0 >> content-length: 217                                                         http-outgoing-0 >> content-type: application/json                                              http-outgoing-0 >> host: targethost:targetport                                                 http-outgoing-0 >> proxy-connection: keep-alive                                                http-outgoing-0 >> user-agent: apache-httpclient/4.5 (java/1.7.0)                              http-outgoing-0 >> expect: 100-continue                                                        http-outgoing-0 >> accept-encoding: gzip,deflate                                               http-outgoing-0 >> proxy-authorization: basic xxxxxxx                                          http-outgoing-0 << http/1.1 400 bad request                                                    http-outgoing-0 << server: squid/3.3.8                                                         http-outgoing-0 << mime-version: 1.0                                                           http-outgoing-0 << date: mon, 31 aug 2015 02:03:28 gmt                                         http-outgoing-0 << content-type: text/html                                                     http-outgoing-0 << content-length: 3166                                                        http-outgoing-0 << x-squid-error: err_invalid_url 0                                            http-outgoing-0 << vary: accept-language                                                       http-outgoing-0 << content-language: en                                                        http-outgoing-0 << x-cache: miss proxyhost                                                http-outgoing-0 << x-cache-lookup: none proxyhost:proxyport                               http-outgoing-0 << via: 1.1 proxyhost (squid/3.3.8)                                            http-outgoing-0 << connection: close     

here snapshot of wireshark capture in "proxy-authorization" header disappeared!

post http://targethost:targetport/uri/ http/1.1 content-length: 217 content-type: application/json host: targethost:targetport proxy-connection: keep-alive user-agent: apache-httpclient/4.5 (java/1.7.0) expect: 100-continue accept-encoding: gzip,deflate 

i tried without expect-continue handshake blow, , works fine 201 response.
requestconfig config = requestconfig.custom() .setproxy(proxy) .setexpectcontinueenabled(false) .build();

anyone understand why fails expect-continue on authorized http proxy? if need set expect-continue attribute, how overcome problem?

thanks lot!


Comments

Popular posts from this blog

c# - Binding a comma separated list to a List<int> in asp.net web api -

Delphi 7 and decode UTF-8 base64 -

html - Is there any way to exclude a single element from the style? (Bootstrap) -