-
Notifications
You must be signed in to change notification settings - Fork 90
HTTP Reader
semsol edited this page May 24, 2011
·
2 revisions
ARC's HTTP Reader can be used as a stand-alone component for generic GET or POST operations. It auto-follows redirects, supports Basic and Digest Authentication, and can be used with TLS.
$conf = array(
...
);
$reader = ARC2::getComponent('Reader', $conf);
$url = 'http://example.com/';
$reader->activate($url);
$path = '../data/test.rdf'; // absolute paths work, too
$reader->activate($path);
The activate() method has to have been called already.
$format = $reader->getFormat(); // e.g. "html", "turtle", "rdfxml", etc.
$doc = '';
while ($buffer = $reader->readStream()) {
$doc .= $buffer;
}
$reader->closeStream();
The Reader uses ARC's normal error hooks.
if ($errs = $reader->getErrors()) {
print_r($errs);
}
$headers = $reader->getResponseHeaders();
$redirs = $reader->getRedirects();
$reader->setHTTPMethod('POST');
$reader->setMessageBody('a=foo&b=bar');
$reader->activate($url);
This is very low-level. Make sure your header code is valid.
// override all custom headers
$reader->setCustomHeaders("Accept: x-turtle; q=0.98");
// append header code
$reader->addCustomHeaders("x-test1: foo\r\nx-test2: bar")
Use a (single) colon to separate the user name from the password.
$conf = array(
'arc_reader_credentials' => array(
'twitter.com' => 'user:pass',
)
);
$reader = ARC2::getComponent('Reader', $conf);
Use 2 colons to separate the user name from the password.
$conf = array(
'arc_reader_credentials' => array(
'api.talis.com/stores/johndoe/meta' => 'johndoe::pass',
)
);
$reader = ARC2::getComponent('Reader', $conf);
All configuration options that start with "arc_reader_ssl_" will be added to the PHP Stream Context if the PHP engine supports "stream_socket_client".
$conf = array(
'arc_reader_ssl_local_cert' => '/some/path/to/somecertAndKey.pem',
'arc_reader_ssl_passphrase' => 'somePass',
'arc_reader_ssl_allow_self_signed' => true,
);
$reader = ARC2::getComponent('Reader', $conf);