- try {
- SGMetar *m = new SGMetar(argv[i], proxy_host, proxy_port, "", time(0));
+ try
+ {
+ static const std::string NOAA_BASE_URL =
+ "http://weather.noaa.gov/pub/data/observations/metar/stations/";
+ HTTP::MemoryRequest* mr = new HTTP::MemoryRequest
+ (
+ NOAA_BASE_URL
+ + boost::to_upper_copy<std::string>(argv[i]) + ".TXT"
+ );
+ HTTP::Request_ptr own(mr);
+ http.makeRequest(mr);
+
+ // spin until the request completes, fails or times out
+ SGTimeStamp start(SGTimeStamp::now());
+ while (start.elapsedMSec() < 8000) {
+ http.update();
+ if( mr->isComplete() )
+ break;
+ SGTimeStamp::sleepForMSec(1);
+ }
+
+ if( !mr->isComplete() )
+ throw sg_io_exception("metar download timed out");
+ if( mr->responseCode() != 200 )
+ {
+ std::cerr << "metar download failed: "
+ << mr->url()
+ << " (" << mr->responseCode()
+ << " " << mr->responseReason() << ")"
+ << std::endl;
+ throw sg_io_exception("metar download failed");
+ }
+
+ SGMetar *m = new SGMetar(mr->responseBody());
+