Sales: 13 19 60    Support: 1300 786 068    Billing: 1300 855 006
Search For: 
Making Outbound Connections from a Hosted Domain
MyHelp Home > Hosting > Website Scripts & Software > Making Outbound Connections from a Hosted Domain

Labels: 

Added by Westnet (Brent Criddle) , last edited by Westnet (Aaron Roots) on Apr 03, 2008  (view change)

If your site needs to connect to an external address, your code will need to make use of our proxy server, as our web servers use a firewall to limit outbound connections. Our proxy server is available at:

Address: proxy.web.westnet.com.au
Port: 3128

There are a number of ways to do this in your code:

PHP

If you're on our Linux web servers, you will need to use PHP:

<?php
	function proxy_url($url, $post_data=NULL, $debug=0)
	{
       	$ch = curl_init();
		curl_setopt ($ch, CURLOPT_PROXY, "http://proxy.web.westnet.com.au:3128");
		curl_setopt ($ch, CURLOPT_URL, $url);

		if ($debug)
		{
			curl_setopt ($ch, CURLOPT_HEADER, 1);
		}
		curl_setopt ($ch, CURLOPT_RETURNTRANSFER, 1);
		curl_setopt ($ch, CURLOPT_FOLLOWLOCATION, 1);
		curl_setopt ($ch, CURLOPT_TIMEOUT, 120);

		if ($post_data != NULL)
		{
			$o="";
			foreach ($post_data as $k=>$v)
			{
				$o.= "$k=".utf8_encode($v)."&";
			}
			$post_data=substr($o,0,-1);
			curl_setopt($ch, CURLOPT_POST, 1);
			curl_setopt($ch, CURLOPT_POSTFIELDS, $post_data);
		}
		else if ($debug)
		{
			echo "\n<br>\$postdata was not array: $post_data<br>\n";
		}

		$result = curl_exec ($ch);

		if ($debug)
		{
			echo "<pre>";
			print_r(curl_getinfo($ch));
			print_r(curl_error($ch));
			echo "</pre>";
		}

		curl_close($ch);
		return $result;
	}


/* TEST EXAMPLE */
	//VARIABLES
	$url_page = "http://www.google.com/"; // set to Required URL

	$post_data = array(
		"key1"=>"value1",
		"key2"=>"value2"
	); //set key/value pairs for post

	$debug = 1;

	//CALLING THE FUNCTION - Google will error with POST data as it does not accept POST requests - but this is an example ONLY
	//POST request (normal use)
	$string = proxy_url($url_page, $post_data);

	//GET request (normal use)
	//$string = proxy_url($url_page);

	//POST request (with debugging info)
	//$string = proxy_url($url_page, $post_data, $debug);

	//GET request (with debugging info)
	//$string = proxy_url($url_page, NULL, $debug);

	// print to output (ie display in browser)
	echo $string;
/**/
?>


ASP.NET

If you're on our Windows servers, you can do this using ASP.NET. In the web.config file, add the following lines:

<system.net>
  <defaultProxy>
  <proxy proxyaddress="http://proxy.web.westnet.com.au:3128" bypassonlocal="true"/>
  </defaultProxy>
</system.net>

Or do it in your code:

'Create the HttpWebRequest object
Dim req as HttpWebRequest = WebRequest.Create(URL)

'Create the proxy class instance
Dim prxy as New WebProxy("http://proxy.web.westnet.com.au:3128")

'Specify that the HttpWebRequest should use the proxy server
req.Proxy = prxy

Try
  'Get the data as an HttpWebResponse object
  Dim resp as HttpWebResponse = req.GetResponse()

  ... work with results ...
Catch wex as WebException
  ...
End Try

Classic ASP

You can also use classic ASP:

<%
Dim objWinHttp
Dim strHTML

Set objWinHttp = Server.CreateObject("WinHttp.WinHttpRequest.5.1")

' Set proxy details
objWinHttp.SetProxy "2","proxy.web.westnet.com.au:3128"

'  .Open(bstrMethod, bstrUrl \[, varAsync])
objWinHttp.Open "GET", http://exampledomain.com/index.html

' Send it on it's merry way.
objWinHttp.Send

' Print out the request status:
Response.Write "Status: " & objWinHttp.Status & " " _
            & objWinHttp.StatusText & "<br />"

' Get the text of the response.
strHTML = objWinHttp.ResponseText

' Trash our object now that we are finished with it.
Set objWinHttp = Nothing
%>

<h1>Here's the page:</h1>
<table border="1">
<tr><td>
<pre>
<%= Server.HTMLEncode(strHTML) %>
</pre>
</td></tr>
</table>


For more information regarding the above, please contact Westnet Domains at domains@westnet.com.au or call 1300 137 480 during business hours.


Powered by Atlassian Confluence 2.7.3, the Enterprise Wiki. Contact Administrators

© Westnet Pty Ltd. All Rights Reserved