How to handle redirect by httpClient fluent? -


i'm writing acceptance tests httpclient fluent api , have trouble.

@when("^i submit delivery address , delivery time$") public void i_submit_delivery_address_and_delivery_time() throws throwable {      response response = request             .post("http://localhost:9999/food2go/booking/placeorder")             .bodyform(                     param("deliveryaddressstreet1",                             deliveryaddress.getstreet1()),                     param("deliveryaddressstreet2",                             deliveryaddress.getstreet2()),                     param("deliverytime", deliverytime)).execute();     content = response.returncontent();     log.debug(content.tostring()); } 

this code works when use post-forward strategy, exception thrown when use redirect instead.

org.apache.http.client.httpresponseexception: found 

what want getting content of redirected page. idea appreciate, in advance.

the http specification requires entity enclosing methods such post , put redirected after human intervention only. httpclient honors requirement default. .

10.3 redirection 3xx     class of status code indicates further action needs    taken user agent in order fulfill request.  action    required may carried out user agent without interaction    user if , if method used in second request    or head.  

...

   if 302 status code received in response request other    or head, user agent must not automatically redirect    request unless can confirmed user, since might    change conditions under request issued. 

one can use custom redirect strategy relax restrictions on automatic redirection if necessary.

    defaulthttpclient client = new defaulthttpclient();     client.setredirectstrategy(new laxredirectstrategy());     executor exec = executor.newinstance(client);     string s = exec.execute(request             .post("http://localhost:9999/food2go/booking/placeorder")             .bodyform(...)).returncontent().asstring(); 

Comments

Popular posts from this blog

c# - Send Image in Json : 400 Bad request -

jquery - Fancybox - apply a function to several elements -

An easy way to program an Android keyboard layout app -