Get a Get in webclient by passing json as parameter

-2

I am making the request this way, but I am not having success, someone who has already 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 in another attempt, but I also passed the url, and it 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)

    
asked by anonymous 19.07.2018 / 20:02

1 answer

1

You need to replace \" with \\" :

 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 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 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 );
    
23.07.2018 / 15:34