Bing maps proxy script example..?

85 views
Skip to first unread message

andr01dm

unread,
Apr 26, 2010, 2:08:07 PM4/26/10
to UMapper
Hello.

I'm creating a UMap app using Flex, and have learned that in order to
create routes with Bing I need to enable MapPointProxy, which in turn
needs to point to a proxy service PHP script on a web server.

Can anyone give me an example of this PHP script?

Thank you.

-[andr01dm]-

--
You received this message because you are subscribed to the Google Groups "UMapper" group.
To post to this group, send email to uma...@googlegroups.com.
To unsubscribe from this group, send email to umapper+u...@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/umapper?hl=en.

Andrei

unread,
Apr 27, 2010, 2:18:03 PM4/27/10
to UMapper
Here is the sample proxy file http://umapper.googlegroups.com/web/msproxy.php
(or see Goup's files)

andr01dm

unread,
Apr 27, 2010, 2:51:09 PM4/27/10
to UMapper
Thank you. :)

-[a]-


On Apr 27, 2:18 pm, Andrei <and...@umapper.com> wrote:
> Here is the sample proxy filehttp://umapper.googlegroups.com/web/msproxy.php

Catalin Stefan

unread,
Apr 9, 2013, 8:27:04 AM4/9/13
to uma...@googlegroups.com, and...@umapper.com
Can we still use the proxy file approach?(with bing token....). If so can you re-post the sample proxy file?
I would prefer to use the approach with the bing key only....but that is only in the API 2.0 right?...and its not released?

Thanks

Erich Erlangga

unread,
Apr 11, 2013, 6:44:29 PM4/11/13
to uma...@googlegroups.com
Here is msproxy.php from the former umapper googlegroups files repository.

<?php

// MaPoint Credentials
$username = "134571";
$password = "sddl349>Jutm.4";
$auth = array(
"nonce" => "", 
"qop" => "",
"realm" => "",
"count" => 0
);
if (isset($_POST["endpoint"]))
{
// get request parameters
$request = stripslashes($_POST["data"]);
$name = $_POST["name"];
$endpoint = $_POST["endpoint"];
// extract host and uri
preg_match("/(^http:\/\/|^)([\w.]+)(\S+)/i", $endpoint, $matches) or die("Incorrect endpoint url: $endpoint");
$proto = $matches[1];
$host = $matches[2];
$uri = $matches[3];
// check protocol
if ($proto != "http://" && $proto != "") die("Incorrect endpoint protocol, need http://");
if ($request != "")
{
// replace [CLIENT_IP] with actual ip
$request = str_replace("[CLIENT_IP]", getRealIpAddr(), $request);
$result = postRequest($request, $name);
if (!$result)
{
$result = postRequest($request, $name);
if (!$result)
{
die("Can't post data\n");
}
}
}
else
{
$result = restRequest();
if (!$result)
{
die("Invalid request.");
}
}
print "$result";
}
function postRequest($request, $name)
{
global $host, $uri;
// calculate valid response
$auth_header = getAuthHeader("POST");
$req = "POST $uri HTTP/1.1\r\n";
$req .= "Host: $host\r\n";
$req .= "Connection: Close\r\n";
if (strlen($auth_header) > 0) $req .= "Authorization: $auth_header\r\n";
$req .= "Content-Type: text/xml; charset=utf-8\r\n";
$req .= "Content-Length: " . strlen($request) . "\r\n";
$req .= "SOAPAction: \"" . $name . "\"\r\n";

$req .= "\r\n";
$req .= $request;
$result = sendAndRecieve($host, $req);
if (!$result) return 0;
// get status
if (!preg_match("/HTTP\/1.1 (\d\d\d) \w+/", $result, $matches)) return 0;
$status = $matches[1];
if ($status == 401)
{
if (!getNonce($result))
{
die ("Unable to get auth info!\n");
}
return 0;
}
else
{
// return only bottom part, response content
$parts = explode("\r\n\r\n", $result);
return $parts[1];
}
}
function restRequest()
{
global $host, $uri;
$req = "GET $uri HTTP/1.1\r\n";
$req .= "Host: $host\r\n";
$req .= "Connection: Close\r\n";
$req .= "\r\n";
$result = sendAndRecieve($host, $req);
if (!$result) return 0;
// get status
if (!preg_match("/HTTP\/1.1 (\d\d\d) \w+/", $result, $matches)) return 0;
$status = $matches[1];
if ($status != 200)
{
return 0;
}
// return response body
$parts = explode("\r\n\r\n", $result);
return $parts[1];
}
// perfomes a simple request without authentication to get the nonce
function getNonce($result)
{
global $auth;
if (!$result) return 0;
// parse result
$pattern = '/(\w+)="(\w+)"/';
if (!preg_match_all($pattern, $result, $matches))
{
return 0;
}
$names = $matches[1];
$values = $matches[2];
for ($idx = 0; $idx < count($names); $idx++) 
{
$auth[$names[$idx]] = $values[$idx];
}
// back to 0
$auth["count"] = 0;
return 1;
}
// calculates valid auth header for digest authentication
function getAuthHeader($type)
{
global $username, $password;
global $auth;
global $uri;
if ($auth["nonce"] == "") return "";
// calculate cnonce and ncount
$cnonce = substr(md5(time()), 16);
$ncount = str_pad(dechex(++$auth["count"]), 8, "0", STR_PAD_LEFT);
$str = "Digest ";
$str .= "username=\"" . $username . "\", ";
$str .= "realm=\"" . $auth["realm"] . "\", ";
$str .= "nonce=\"" . $auth["nonce"] . "\", ";
$str .= "qop=\"" . $auth["qop"] . "\", ";
$str .= "uri=\"" . $uri . "\", ";
// calculate response
$ha1 = md5($username . ":" . $auth["realm"] . ":" . $password);
$ha2 = md5($type . ":" . $uri);
$response = md5($ha1 . ":" . $auth["nonce"] . ":" . $ncount . ":" . $cnonce . ":" . $auth["qop"] . ":" . $ha2);
$str .= "response=\"" . $response . "\", ";
$str .= "nc=\"" . $ncount . "\", ";
$str .= "cnonce=\"" . $cnonce . "\"";
return $str;
}
// send the data to socket and recives the answer
function sendAndRecieve($host, $request)
{
$fp = fsockopen($host, 80, $errno, $errstr, 30);
if (!$fp) 
{
die ("Can't open socket to $host:80");
}
fwrite($fp, $request);
$answer = "";
while (!feof($fp)) 
{
$answer .= fgets($fp, 128);
}
fclose($fp);
return $answer;
}
// find out the real ip address
function getRealIpAddr()
{
if (!empty($_SERVER['HTTP_CLIENT_IP']))   //check ip from share internet
{
 $ip=$_SERVER['HTTP_CLIENT_IP'];
}
elseif (!empty($_SERVER['HTTP_X_FORWARDED_FOR']))   //to check ip is pass from proxy
{
 $ip=$_SERVER['HTTP_X_FORWARDED_FOR'];
}
else
{
 $ip=$_SERVER['REMOTE_ADDR'];
}
return $ip;
}
?>


To unsubscribe from this group and stop receiving emails from it, send an email to umapper+u...@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.
 
 

Reply all
Reply to author
Forward
0 new messages