System.Net.WebException: The remote name could not be resolved: 'test.authorize.net' at System.Net.HttpWebRequest.GetRequestStream(TransportContext& context) at System.Net.HttpWebRequest.GetRequestStream()
I gets the above error when it fires the Credit card API on server while it works totally fine on local.
error comes at
:
StreamWriter myWriter = null;
myWriter = new StreamWriter(objRequest.GetRequestStream());
myWriter.Write(post_string);
myWriter.Close();
Full code is:
protected void Page_Load(object sender, EventArgs e)
{
String post_url = "https://test.authorize.net/gateway/transact.dll";
Dictionary<string, string> post_values = new Dictionary<string, string>();
post_values.Add("x_login", "API_LOGIN_ID");
post_values.Add("x_tran_key", "TRANSACTION_KEY");
post_values.Add("x_delim_data", "TRUE");
post_values.Add("x_delim_char", "|");
post_values.Add("x_relay_response", "FALSE");
post_values.Add("x_type", "AUTH_CAPTURE");
post_values.Add("x_method", "CC");
post_values.Add("x_card_num", "4111111111111111");
post_values.Add("x_exp_date", "0115");
post_values.Add("x_amount", "19.99");
post_values.Add("x_description", "Sample Transaction");
post_values.Add("x_first_name", "John");
post_values.Add("x_last_name", "Doe");
post_values.Add("x_address", "1234 Street");
post_values.Add("x_state", "WA");
post_values.Add("x_zip", "98004");
String post_string = "";
foreach (KeyValuePair<string, string> post_value in post_values)
{
post_string += post_value.Key + "=" + HttpUtility.UrlEncode(post_value.Value) + "&";
}
post_string = post_string.TrimEnd('&');
HttpWebRequest objRequest = (HttpWebRequest)WebRequest.Create(post_url);
objRequest.Method = "POST";
objRequest.ContentLength = post_string.Length;
objRequest.ContentType = "application/x-www-form-urlencoded";
StreamWriter myWriter = null;
myWriter = new StreamWriter(objRequest.GetRequestStream());
myWriter.Write(post_string);
myWriter.Close();
String post_response;
HttpWebResponse objResponse = (HttpWebResponse)objRequest.GetResponse();
using (StreamReader responseStream = new StreamReader(objResponse.GetResponseStream()) )
{
post_response = responseStream.ReadToEnd();
responseStream.Close();
}
Array response_array = post_response.Split('|');
resultSpan.InnerHtml += "<OL> \n";
foreach (string value in response_array)
{
resultSpan.InnerHtml += "<LI>" + value + " </LI> \n";
}
resultSpan.InnerHtml += "</OL> \n";
}