Creating a GET request with matrix parameters

2019-03-02 04:50发布

问题:

The webservice I'll be using expects matrix parameters:

http://tester.com/v1/customers;lastname=Jackson;firstname=Tim;bookingreference=7Y9UIY

instead of the usual

http://tester.com/v1/customers?lastname=Jackson&firstname=Tim&bookingreference=7Y9UIY

Is there anyway I can create a request using the Spring UriComponentsBuilder or an alternative?

I'm aware that I could just create it manually but hoped there was something more streamlined available.

回答1:

UriBuilder and WebTarget of JAX-RS allow to add matrix params.

 UriBuilder builder = ...
 builder.matrixParam("lastname", "Jackson").matrixParam("firstname", "Tim")...


回答2:

Try with the given().urlEncodingEnabled(false) This resolved my problem . After giving that the matrix parameter issue got resolved and able to hit the service properly