Home > database >  Pass parameters in post http request
Pass parameters in post http request

Time:06-14

I want to pass variables in Java Rest API The Post URL is : ex: https://localhost:8080/webresources/test?id=.....

This is my current code:

@POST
@Path("test")    
public String newRequest() throws ServletException, IOException, JSONException {
        ...
 }

How should I pass my parameter to call my request like this : newRequest(123);

CodePudding user response:

You want to add @QueryParam for query parameters, as:

public String newRequest(@QueryParam("id") String request_sf_id) throws ServletException, IOException, JSONException { ..} 

Binds the value(s) of a HTTP query parameter to a resource method parameter, resource class field, or resource class bean property.

CodePudding user response:

You can use RequestParam:

@POST
@Path("test")    
public String newRequest(@RequestParam(value ="id") String id) throws ServletException, IOException, JSONException {
        ...
 }

And calling :

https://localhost:8080/webresources/test?id=.....

Please note, RequestParam is part of spring so you need :

import org.springframework.web.bind.annotation.RequestParam;
  • Related