URLCP HEADER QUESTION

Post Reply
gerry.odea
Posts: 98
Joined: Fri Sep 19, 2008 9:33 am

URLCP HEADER QUESTION

Post by gerry.odea »

I am trying to include this in my header request.

The sample I have is from PHP.
'header' => "Authorization: Basic " . base64_encode($accountKey . ":" . $accountKey)

I need to know how I would write this with <urlcp header> as I am totally stumped. Could you please help me. Thank you!

PS. It is for the new BING API here is the full PHP sample

<html>
<head>
<link href="styles.css" rel="stylesheet" type="text/css" />
<title>PHP Bing</title>
</head>
<body>
<form method="post" action="<?php echo $_SERVER['PHP_SELF'];?>">
Type in a search:

<input type="text" id="searchText" name="searchText"
value="<?php
if (isset($_POST['searchText']))

{
echo($_POST['searchText']);
}
else
{
echo('sushi');
}
?>"
/>

<input type="submit" value="Search!" name="submit" id="searchButton" />
<?php
if (isset($_POST['submit']))
{
// Replace this value with your account key
$accountKey = 'AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA=';

$ServiceRootURL = ‘https://api.datamarket.azure.com/Bing/Search/';

$WebSearchURL = $ServiceRootURL . 'Image?$format=json&Query=';

$context = stream_context_create(array(
'http' => array(
'proxy' => 'tcp://127.0.0.1:8888',
'request_fulluri' => true,
'header' => "Authorization: Basic " . base64_encode($accountKey . ":" . $accountKey)
)
));

$request = $WebSearchURL . urlencode( '\'' . $_POST["searchText"] . '\'');

echo($request);

$response = file_get_contents($request, 0, $context);

$jsonobj = json_decode($response);

echo('<ul ID="resultList">');

foreach($jsonobj->d->results as $value)
{
echo('<li class="resultlistitem"><a href="' . $value->MediaURL . '">');

echo('<img src="' . $value->Thumbnail->MediaUrl. '"></li>');
}

echo("</ul>");
}
?>
</form>
</body>
</html>
User avatar
Kai
Site Admin
Posts: 1271
Joined: Tue Apr 25, 2000 1:27 pm

URLCP HEADER QUESTION

Post by Kai »

You can use the %B format code to base64-encode the key:

<strfmt "%s:%s" $accountKey $accountKey>
<strfmt "Basic %B" $ret>
<urlcp header "Authorization" $ret>
<fetch ...>
gerry.odea
Posts: 98
Joined: Fri Sep 19, 2008 9:33 am

URLCP HEADER QUESTION

Post by gerry.odea »

What if I just have Commercial Version 2.6.929642470 and %B is not supported in that version. Is there a way to hardcode the base64-encode? And how would i do that?
User avatar
mark
Site Admin
Posts: 5513
Joined: Tue Apr 25, 2000 6:56 pm

URLCP HEADER QUESTION

Post by mark »

With that stoneage version you'll need to <exec> some utility to do the encoding for you. Unless you want to try writing the encoder in vortex. Eek, did I say that out loud... ;-)
gerry.odea
Posts: 98
Joined: Fri Sep 19, 2008 9:33 am

URLCP HEADER QUESTION

Post by gerry.odea »

it stays the same every time so I just went to a site that 64 bit encodes and just encoded it. I have another question about this:

Unknown access method `https' for URL https://api.datamarket.azure.com/Data.a ... ormat=Atom in the function htcreaterequest

what could be causing this? and how can I fixed it?
User avatar
mark
Site Admin
Posts: 5513
Joined: Tue Apr 25, 2000 6:56 pm

URLCP HEADER QUESTION

Post by mark »

Sounds like upgrade time. I don't think https was supported in your pre 2000 version.
Post Reply