現在、米国郵政公社の Web Tools APIを使用してユーザーの住所を検証しようとしています。ただし、Web サービスに接続するために使用する情報の組み合わせや手法に関係なく、同じ例外が発生します。
Unable to connect to the remote service
同じ内部例外で
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
ただし、C#WebClient
オブジェクトを使用するのは初めてです。ここで私が間違っていることを誰かが見ることができますか?
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;
}