Get into Webclient by passing json as parameter

Asked

Viewed 329 times

-2

I’m doing the requisition this way, but I’m not succeeding , someone who’s been through it?

private static String vwsApiUrl = "http://vws.veloxtickets.com:82/wscinema.ws/Get_Cinema_Programacao";

 String url = "'{\"AUTENTICACAO\":{\"USUARIO\":\"SONAE\",\"SENHA\":\"senha\"},\"GETPROG\":{\"DATAINI\":\"2018-07-05\",\"DATAFIN\":\"2018-07-08\",\"CODPRACA\":\"PLZ\"}}'";

 Disposable webClient = WebClient.create(vwsApiUrl  )
                .method (  HttpMethod.GET)
                .uri ( vwsApiUrl + url)
                .contentType ( MediaType.APPLICATION_JSON_UTF8)
                .accept ( MediaType.APPLICATION_JSON_UTF8 )
                .exchange ()
                .flatMap ( clientResponse ->  clientResponse.bodyToMono ( String.class ) ).subscribe ( System.out::println );

This json was another attempt , but I passed tbm the url ,and returns an error :

Exception in thread "restartedMain" java.lang.reflect.Invocationtargetexception Caused by: java.lang.Illegalargumentexception: Not enough variable values available to expand '"DATAINI"' at org.springframework.web.util.Uricomponents$Varargstemplatevariables.getValue(Uricomponents.java:352) at org.springframework.web.util.Uricomponents.expandUriComponent(Uricomponents.java:252)

  • 1

    Enter a little more context, so the reader can identify better. What do you search for? What’s the ? How ? what do you use ?

  • .uri ( vwsApiUrl + json ) - are you sure this is what you wanted? Note that your JSON is in the variable url that you don’t use anywhere, while the variable json, Only with that code can’t tell what it is because it’s not set anywhere. Also I think that concatenating a JSON into the URL like this is something strange to say the least.

  • Are you getting some error doing this?

1 answer

1

You need to replace the \" for \\\":

 String url = "'{\"AUTENTICACAO\":{\"USUARIO\":\"SONAE\",\"SENHA\":\"senha\"},\"GETPROG\":{\"DATAINI\":\"2018-07-05\",\"DATAFIN\":\"2018-07-08\",\"CODPRACA\":\"PLZ\"}}'";
 String urlEscapada = url.replace("\"", "\\\"");

Difference between url and the urlEscapada, respectively:

'{"AUTENTICACAO":{"USUARIO":"SONAE","SENHA":"senha"},"GETPROG":{"DATAINI":"2018-07-05","DATAFIN":"2018-07-08","CODPRACA":"PLZ"}}'

'{\"AUTENTICACAO\":{\"USUARIO\":\"SONAE\",\"SENHA\":\"senha\"},\"GETPROG\":{\"DATAINI\":\"2018-07-05\",\"DATAFIN\":\"2018-07-08\",\"CODPRACA\":\"PLZ\"}}'

Using the urlEscapada:

Disposable webClient = WebClient.create(vwsApiUrl  )
            .method (  HttpMethod.GET)
            .uri ( vwsApiUrl + urlEscapada)
            .contentType ( MediaType.APPLICATION_JSON_UTF8)
            .accept ( MediaType.APPLICATION_JSON_UTF8 )
            .exchange ()
            .flatMap ( clientResponse ->  clientResponse.bodyToMono ( String.class ) ).subscribe ( System.out::println );

Browser other questions tagged

You are not signed in. Login or sign up in order to post.