Strange to be having this problem, but I haven't scripted much of anything in years. It's probably a simple answer, but I'm out of ideas.
I'm trying to update an old weather script to use Open Weather Map for it's data. I connect fine to the server using sockets. However, when I try looking at the raw data, I run into a problem. If I get the data in HTML format, I receive all of the data as expected, but if I choose XML format, it gives me only the header line and nothing else. If I choose JSON format, I don't get anything. Here is the raw XML output:
HTTP/1.1 200 OK
Server: openresty
Date: Fri, 14 Feb 2020 02:36:44 GMT
Content-Type: application/xml; charset=utf-8
Content-Length: 871
Connection: close
X-Cache-Key: /data/2.5/weather?mode=xml&q=01613,us&units=imperial
Access-Control-Allow-Origin: *
Access-Control-Allow-Credentials: true
Access-Control-Allow-Methods: GET, POST
<?xml version="1.0" encoding="UTF-8"?>
That last line is the header line for the XML. But I get nothing else. Here's the correct output if I view this same GET through the browser:
<?xml version="1.0" encoding="UTF-8"?>
<current><city id="4956184" name="Worcester"><coord lon="-71.83" lat="42.28"></coord><country>US</country><timezone>-18000</timezone><sun rise="2020-02-13T11:47:14" set="2020-02-13T22:16:03"></sun></city><temperature value="34.97" min="33.01" max="37.4" unit="fahrenheit"></temperature><feels_like value="23.47" unit="fahrenheit"></feels_like><humidity value="86" unit="%"></humidity><pressure value="1006" unit="hPa"></pressure><wind><speed value="13.87" unit="mph" name="Moderate breeze"></speed><gusts></gusts><direction value="280" code="W" name="West"></direction></wind><clouds value="90" name="overcast clouds"></clouds><visibility value="16093"></visibility><precipitation value="0.25" mode="rain" unit="1h"></precipitation><weather number="500" value="light rain" icon="10n"></weather><lastupdate value="2020-02-14T02:27:11"></lastupdate></current>
As I mentioned, if I request the weather with HTML mode instead of XML, I get all of the data, so the socket is working properly. But for some reason, the XML isn't reading past the header. Any ideas? I know I could use HTML, but I want to know why it isn't working for XML or JSON modes.
Sockread code is simply this for testing:
on *:sockread:weather: {
if ($sockerr) {
echo -a Error.
halt
}
else {
var %temptext
sockread %temptext
echo -a %temptext
}
}