Question
· Jul 10, 2019

OpenWeathermap http error when making REST call

Hello ,

I am trying to make a REST call using the example given in documentation for Creating REST Services and Clients with Ensemble.

Class Test.REST.WeatherOperation Extends EnsLib.REST.Operation

But i receive below mentioned error. If anyone can help me out here.

 

ERROR <Ens>ErrGeneral: ERROR <Ens>ErrHTTPStatus: Received non-OK status 404 from remote HTTP server: 'HTTP/1.1 404 Not Found':<html>
<head><title>404 Not Found</title></head>
<body bgcolor="white">
<center><h1>404 Not Found</h1></center>
<hr><center>nginx</center>
</body>
</html>

 

Thanks,

Jimmy Christian.

Discussion (6)0
Log in or sign up to continue

Yes, Thank you. I just corrected the URL and it works now. Thank you Robert.  One more question if you can assist in this context.

So the response message i got back is in the HttpResponse object.

How can i convert the HttpResponse.Data property to JSON and parse the values. Since the data i received is Stream, is there a way i can convert the stream to Dynamic Objects and parse  it?

Thank you.

Jimmy Christian.

the data property is a standard HTML page.
I'm not aware of some function in Caché that converts HTML to JSON.

But asking Google "convert HTML to JSON"  shows that this a standard feature in JavaScript. 
so I see 2 options:

- write your own parser (or someone in the community has done this before ???

- call an external tool (eg. node.js) to it for you

see:   https://stackoverflow.com/questions/34504050/how-to-convert-selected-html-to-json

or  https://stackoverflow.com/questions/12980648/map-html-to-json

or https://stackoverflow.com/questions/43469412/convert-html-source-code-to-json-object

Hello Eduard,

i was able to convert the HttpResponse.Data to String and than to the Dynamic Object. Worked great. Thank you.

On the same line, i need to ask you of any template or suggestion to send a JSON data to a REST API.

For eg. below is the JSON

{"name":"abcdefghi","salary":"123","age":"23"}

How do i send it to  http://testing.restapiexample.com/api/v1/createemployee with POST request using the  set tSC=..Adapter.PostURL(tConfig.URL,.tHTTPResponse,,pRequest)

Below code is not working.

Set pRequest=."{"name":"abcdefghi","salary":"123","age":"23" }"

Your help will be appreciated.

Thanks,

Jimmy Christian.