David Smart / NWSWeather
Revision:
12:d70de07ca914
Parent:
11:98afc5abbfb8
Child:
13:a9ac9dde4f7f
diff -r 98afc5abbfb8 -r d70de07ca914 NWSWeather.cpp
--- a/NWSWeather.cpp	Thu Aug 06 11:12:15 2015 +0000
+++ b/NWSWeather.cpp	Thu Nov 26 18:58:29 2015 +0000
@@ -1,7 +1,7 @@
 // 
 // This file contains the interface for gathering forecast from NWS.
 //
-// attention: This program is copyright (c) 2014 by Smartware Computing, all 
+// attention: This program is copyright (c) 2014 - 2015 by Smartware Computing, all 
 // rights reserved.
 // 
 // This software, and/or material is the property of Smartware Computing. All
@@ -16,7 +16,7 @@
 //
 #include "NWSWeather.h"
 
-#define DEBUG "NWS "
+//#define DEBUG "NWS "
 // ...
 // INFO("Stuff to show %d", var); // new-line is automatically appended
 //
@@ -30,6 +30,15 @@
 #define ERR(x, ...)
 #endif
 
+// 20151126 - Not sure when, but the NWS site stopped accepting requests unless a
+//            User-Agent was provided. It doesn't seem to matter the contents of
+//            the U-A string.
+static const char * hdrs[] = {
+    "Connection", "keep-alive",
+    "Accept", "text/html",
+    "User-Agent", "SW_Client"
+};
+#define HDR_PAIRS 3
 
 static NWSWeather::XMLItem_T WeatherData[] = {
     {"observation_time_rfc822", NWSWeather::isString},
@@ -97,7 +106,7 @@
     NWSReturnCode_T retCode = nomemory;
     char *url = NULL;
     char *message = (char *)malloc(responseSize);
-
+    
     INFO("get(%s)", site);
     if (!message)
         ERR("failed to malloc(%d)", responseSize);
@@ -111,6 +120,7 @@
             strcat(url, ".xml");
             INFO("  url: %s", url);
             http.setMaxRedirections(3);
+            http.customHeaders(hdrs, HDR_PAIRS);
             int ret = http.get(url, message, responseSize);
             if (!ret) {
                 INFO("ret is %d", ret);