Reputation: 31
http://www.mkyong.com/webservices/jax-rs/restful-java-client-with-jersey-client/
I used this link to make a rest call from my application. Here I can pass one object as an input parameter.
Client client = Client.create();
WebResource webResource = client .resource("http://localhost:8080/RESTfulExample/rest/json/metallica/post");
String input = "{\"singer\":\"Metallica\",\"title\":\"Fade To Black\"}";
ClientResponse response = webResource.type("application/json") .post(ClientResponse.class, **input**);
I need to pass multiple input parameters (like image,string, etc) in the place of input but not as one object. How could I resolve this issue?
Upvotes: 0
Views: 7840
Reputation: 3960
If you want to have multiple parts with other types you should use Multipart, you can find more about here. So you can have an image part and two String parts for example.
You can also send your image as an Base64 String inside your object but that will increase the size of it. A better way is to pass the byte[] inside the object.
A possibility is to send all this data as multiple query params but that will be very bad also the size of the url is limited.
Upvotes: 1
Reputation: 2168
Study more about various HTTP methods and the request response model of HTTP. Wikipedia is a good starting point: https://en.wikipedia.org/wiki/Hypertext_Transfer_Protocol
Usually data is passed from client to server in the below fashion:
Content-Type
HTTP header. Read more about various content types at What are all the possible values for HTTP "Content-Type" header?If you need to send various content-types together, say image and text, just convert the image into a string as a byte array and send that along with text.
Upvotes: 0