XML response handling from web request

fixed

#1

Is it possible to do a GET request to a URL that will reply with XML, then act on the data in the reply? So far it doesn’t seem that any data is saved in the $response variable to this endpoint, so I can’t even go from there. Maybe this is asking too much from webcore?


#2

isnt there a set of $http* variables? have you checked those?


#3

webCoRE has special handling for JSON responses, but you should be able to use $response as text regardless of the content type. However, the $response variable is only populated if the service responds with a 200 OK status. If the $httpStatusCode variable has the value 200 after your request then there should be something usable in $response. Granted it may not be a useful as having an XML parser at your disposal but you may be able to use string functions on the text to get what you need.


#4

@ipaterson
IMG_3951


#5


#6

Should I be scared that I actually Grok’d that?


#7

You seemed to know what you were talking about so I wrote for you. I guess these thread hijackers have a point though that writing for anyone to understand is beneficial, even if the topic is parsing XML from web requests :wink:


#8

I wasnt the original poster - but yeah…

99% of my day job is explaining more esoteric points with non-tech people (Head of Cyber/Information Security at a fortune 500 ) so i feel the pain :stuck_out_tongue_winking_eye:

Thinking through this use case, I see a bunch of potential for pulling data from ‘unconnected’ systems - I could in theory pull weather data from my PWS w/out going to Wunderground, simply by going to my own server, and sending a JSON response with HTTP200 (which it should do - potentially unless you get a redirect 301/302 in the way)

Opens up another whole thought process for me - thanks!


#9

In all honesty, while I can’t speak for @Cozdabuch, meme is a lot more related to late night and Scotch than to what you actually wrote :crazy_face:


#10

Ha, oops I guess I’m not paying much attention this morning.


#11

Yo no habla code. Eso es todo.


#12

This is what I’m seeing in my debug logs for the following variables:
$response = [:]
$httpStatusCode = 200
$httpStatusOk = true

Yet if I curl the same url outside webcore, I get 200 OK and XML. Other ideas?


#13

How about $httpContentType?


#14

It appeared to be empty. It didn’t put anything in the logs.


#15

Could you share a sample piston? A private message to me is best if the request requires any API keys or similar that you can’t post publicly.


#16

image
image


#17

try $json


#18

Even just getting back data from this simple test is failing:
image
If I do a curl of the same URL, I get back the text from that document, which is just “test”.


#19

Are your screenshots anonymizing the link or are you trying to make an internal call? All these actions are performed in the ST cloud which is not local. So you would need to point it at your actual IP address and port forward in your router to where you are trying to go.


#20

@alexjhart, the issue here is that webCoRE is not able to access your internal 192.168.* IP addresses since the code runs in the cloud rather than on your local hub. Can you set up port forwarding to make your local service accessible via your public IP, or a dynamic hostname (e.g. noip.com) if your IP is not static?

Edit for future readers: Sorry, clearly this advice was wrong and local requests should work fine.