I am currently trying to use the United States Postal Service's Web Tools API to validate a user's address. However, no matter what combination of information I use or technique to connect to the web service, I get the same exception:
Unable to connect to the remote service
With the same Inner Exception
A connection attempt failed because the connected party did not properly respond after
a period of time, or established connection failed because connected host has failed to
respond 56.0.34.43:443
I am using a C# WebClient
object for the first time, however. Can anyone see something I'm doing wrong here?
private const string USPS_USERID = "xxxxxxx";
private const string BASEURL = "https://secure.shippingapis.com/ShippingAPITest.dll";
try
{
string USPS = BASEURL + "?API=Verify&XML=<AddressValidateRequest USERID=\"" + USPS_USERID + "\">";
USPS += "<Address ID='0'>";
USPS += "<Address1>" + addressInfo[0] + "</Address1>";
USPS += "<Address2>" + addressInfo[1] + "</Address2>";
USPS += "<City>" + addressInfo[2] + "</City>";
USPS += "<State>" + addressInfo[3] + "</State>";
USPS += "<Zip5>" + addressInfo[4] + "</Zip5>";
USPS += "<Zip4></Zip4>";
USPS += "</Address></AddressValidateRequest>";
WebClient wsClient = new WebClient();
byte[] responseData = wsClient.DownloadData(USPS);
string response = string.Empty;
foreach (byte item in responseData)
{
response += (char) item;
}
return Json(response, JsonRequestBehavior.AllowGet);
}
catch (Exception ex)
{
return null;
}