Unable to get JSON from GET request

New in the game! Framework and web development in general, I'm trying to make a simple REST GET for a web service and just get JSON directly in response. By typing the URL in the browser, I get the perfect answer with well-formatted JSON. Calling it by code, it just explodes:

WS.WSRequest wsRequest = WS.url( serviceURL ); wsRequest.timeout( timeoutTime ); wsRequest.setHeader("Accept", "application/json"); wsRequest.headers.put( "Content-type","application/json" ); wsRequest.mimeType = "application/json"; WS.HttpResponse response = wsRequest.get(); String graphServiceResponse = response.getJson().toString(); 

Everything runs fine until the last line throws an exception and errors. I know that I have something like redundant code; these are my attempts to fix it. As I said, typing "serviceURL" in the browser works fine.

Does anyone know what I'm doing wrong? Thanks in advance!

+4
source share
2 answers

Ok, I decided. Just omitted all the sets, etc., Added authentication, and it worked perfectly. Weird

  String stringResponse = ""; try { // execute GET to graph service WS.WSRequest wsRequest = WS.url( serviceURL ).authenticate( USERNAME, PASSWORD ); WS.HttpResponse response = wsRequest.get(); stringResponse = response.getString(); ... more cool stuff ... 

Thanks for watching!

0
source

I tried and found that this code below works. 10000 is the timeout parameter in ms.

  String baseUrl = "your url"; F.Promise<WSResponse> response = ws.url(baseUrl) .setQueryParameter(param, value) .get(); return response.get(10000).asJson().toString(); 
0
source

Source: https://habr.com/ru/post/1399458/


All Articles