On April 1, 2021, we are moving all of our QuotaGuard Support Documentation to
https://quotaguard.github.io/qg-docs/
Please Update Your Support Bookmarks
Documentation for this article will be maintained at
https://quotaguard.github.io/qg-docs/quickstart-dotnet.html
Please click on the above link to ensure you are reading
the most recent and updated documentation.
Installation
When you sign up you will be provided with a unique username and password and a connection string that you can use when configuring your proxy service in your application:
http://username:password@static.quotaguard.com:9293
All requests that you make via this proxy will appear to the destination server to originate from one of the two static IPs you will be assigned when you sign up.
We recommend you store the connection string in an environment variable QUOTAGUARDSTATIC_URL
. If you have signed up via the add-ons platform on Heroku or cloudControl this variable will be automatically set in your production environment.
Integration
This example is written in C# and uses the HttpWebRequest class to make a request via QuotaGuard Static:
using System;
using System.IO;
using System.Net;
using System.Text;
namespace QuotaGuardStaticSample {
class MainClass {
public static void Main (string[] args) {
//Extract proxy connection details
string proxyUrl = Environment.GetEnvironmentVariable("QUOTAGUARDSTATIC_URL");
System.Uri proxyUri = new System.Uri(proxyUrl);
string cleanProxyURL = proxyUri.Scheme + "://" + proxyUri.Host+":"+proxyUri.Port;
string user = proxyUri.UserInfo.Split(':')[0];
string password = proxyUri.UserInfo.Split(':')[1];
HttpWebRequest request = (HttpWebRequest) WebRequest.Create("http://ip.jsontest.com");
WebProxy myProxy = new WebProxy();
Uri newUri = new Uri(cleanProxyURL);
// Associate the newUri object to 'myProxy' object so that new myProxy settings can be set.
myProxy.Address = newUri;
// Create a NetworkCredential object and associate it with the
// Proxy property of request object.
myProxy.Credentials = new NetworkCredential(user, password);
request.Proxy = myProxy;
HttpWebResponse httpWebResponse = request.GetResponse() as HttpWebResponse;
// Get the stream containing content returned by the server.
Stream dataStream = httpWebResponse.GetResponseStream();
// Open the stream using a StreamReader for easy access.
StreamReader streamReader = new StreamReader(dataStream);
// Read the content.
String responseFromServer = streamReader.ReadToEnd();
// Write the content.
Console.WriteLine(responseFromServer);
streamReader.Close();
dataStream.Close();
}
}
}