You are here:  » add http headers to magic parser request


add http headers to magic parser request

Submitted by jp_solspot on Wed, 2015-04-08 07:45 in

is it possible to send a header type within the magic parser call?

We are accessing a server for xml data and the server is currently turning away any request without http 1.1 in the headers. CURL be default does seem to produce http 1.1 headers but we were also required to display a user agent.

We are using the following in the request string:

MagicParser_parse($rss,"myRecordHandler","xml|DWML/");

where $rss is the http url

example $rss=http://forecast.weather.gov/MapClick.php?lat=35.21520&lon=-75.68380&FcstType=xml

Submitted by support on Wed, 2015-04-08 08:42

Hi,

You can use CURL to perform the fetch, and then pass the XML to MagicParser using the string:// operator, for example:

  $rss="http://forecast.weather.gov/MapClick.php?lat=35.21520&lon=-75.68380&FcstType=xml";
  $ch = curl_init($url);
  curl_setopt($ch, CURLOPT_HEADER, 0);
  curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
  $xml = curl_exec($ch);
  MagicParser_parse("string://".$xml,"myRecordHandler","xml|DWML/");

You can add any additional curl_setopt() calls required e.g. CURLOPT_USERAGENT if you require a custom user agent etc..

Hope this helps!
Cheers,
David
--
MagicParser.com

Submitted by jp_solspot on Wed, 2015-04-08 15:31

thanks for the quick reply David! I ended up using ini_set('user_agent', 'agent name');
and all worked great.
-JP