EpicDewd
EpicDewd

Reputation: 385

Request type over curl - Trying to get xml file to output/download correctly

So I'm building an app that phrases an xml file... It needs to get the file with curl.

I'm using this command:

curl -L -o /Users/MyName/Desktop/fileName.xml  http://www.aviationweather.gov/adds/dataserver_current/httpparam?dataSource=metars&requestType=retrieve&format=xml&stationString=KPHX&hoursBeforeNow=1

First off, here's a link to their api

And also here's some of their examples

When I view the data server url in my browser it shows up fine.

http://www.aviationweather.gov/adds/dataserver_current/httpparam?dataSource=metars&requestType=retrieve&format=xml&stationString=KPHX&hoursBeforeNow=1

but when I curl it I get this:

<?xml version="1.0" encoding="UTF-8"?>
<Response>
  <request_index>548652</request_index>
  <data_source name="server" />
  <request type="status" />
  <errors>
    <error>requestType parameter required</error>
  </errors>
  <warnings>
    <warning>Request type not specified, defaulting to status</warning>
    <warning>Data source not specified, defaulting to server</warning>
  </warnings>
  <time_taken_ms>0</time_taken_ms>
  <response />
</Response>

instead of whats showing up in my browser which is this

<?xml version="1.0" encoding="UTF-8"?>
<response xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XML-Schema-instance" version="1.2" xsi:noNamespaceSchemaLocation="http://aviationweather.gov/adds/schema/metar1_2.xsd">
  <request_index>550259</request_index>
  <data_source name="metars" />
  <request type="retrieve" />
  <errors />
  <warnings />
  <time_taken_ms>3</time_taken_ms>
  <data num_results="3">
    <METAR>
      <raw_text>KPHX 120551Z 08007KT 10SM CLR 12/01 A3002 RMK AO2 SLP161 T01170011 10211 20117 58004</raw_text>
      <station_id>KPHX</station_id>
      <observation_time>2014-01-12T05:51:00Z</observation_time>
      <latitude>33.43</latitude>
      <longitude>-112.02</longitude>
      <temp_c>11.7</temp_c>
      <dewpoint_c>1.1</dewpoint_c>
      <wind_dir_degrees>80</wind_dir_degrees>
      <wind_speed_kt>7</wind_speed_kt>
      <visibility_statute_mi>10.0</visibility_statute_mi>
      <altim_in_hg>30.02067</altim_in_hg>
      <sea_level_pressure_mb>1016.1</sea_level_pressure_mb>
      <quality_control_flags>
        <auto_station>TRUE</auto_station>
      </quality_control_flags>
      <sky_condition sky_cover="CLR" />
      <flight_category>VFR</flight_category>
      <three_hr_pressure_tendency_mb>-0.4</three_hr_pressure_tendency_mb>
      <maxT_c>21.1</maxT_c>
      <minT_c>11.7</minT_c>
      <metar_type>SPECI</metar_type>
      <elevation_m>336.0</elevation_m>
    </METAR>
    <METAR>
      <raw_text>KPHX 120451Z 00000KT 10SM CLR 13/01 A3003 RMK AO2 SLP162 T01280006</raw_text>
      <station_id>KPHX</station_id>
      <observation_time>2014-01-12T04:51:00Z</observation_time>
      <latitude>33.43</latitude>
      <longitude>-112.02</longitude>
      <temp_c>12.8</temp_c>
      <dewpoint_c>0.6</dewpoint_c>
      <wind_dir_degrees>0</wind_dir_degrees>
      <wind_speed_kt>0</wind_speed_kt>
      <visibility_statute_mi>10.0</visibility_statute_mi>
      <altim_in_hg>30.029528</altim_in_hg>
      <sea_level_pressure_mb>1016.2</sea_level_pressure_mb>
      <quality_control_flags>
        <auto_station>TRUE</auto_station>
      </quality_control_flags>
      <sky_condition sky_cover="CLR" />
      <flight_category>VFR</flight_category>
      <metar_type>METAR</metar_type>
      <elevation_m>336.0</elevation_m>
    </METAR>
    <METAR>
      <raw_text>KPHX 120351Z 00000KT 10SM CLR 14/01 A3004 RMK AO2 SLP166 T01390006</raw_text>
      <station_id>KPHX</station_id>
      <observation_time>2014-01-12T03:51:00Z</observation_time>
      <latitude>33.43</latitude>
      <longitude>-112.02</longitude>
      <temp_c>13.9</temp_c>
      <dewpoint_c>0.6</dewpoint_c>
      <wind_dir_degrees>0</wind_dir_degrees>
      <wind_speed_kt>0</wind_speed_kt>
      <visibility_statute_mi>10.0</visibility_statute_mi>
      <altim_in_hg>30.041338</altim_in_hg>
      <sea_level_pressure_mb>1016.6</sea_level_pressure_mb>
      <quality_control_flags>
        <auto_station>TRUE</auto_station>
      </quality_control_flags>
      <sky_condition sky_cover="CLR" />
      <flight_category>VFR</flight_category>
      <metar_type>SPECI</metar_type>
      <elevation_m>336.0</elevation_m>
    </METAR>
  </data>
</response>

Sorry if this is kind of a long post, just not the easiest to explain.

Upvotes: 0

Views: 4487

Answers (1)

rul
rul

Reputation: 824

The shell you're using is interpreting the ampersands. Just quote the URL and you'll be able to get the file.

Upvotes: 1

Related Questions