服务器上的信用卡API异常 [英] Credit Card API exception on server

查看:74
本文介绍了服务器上的信用卡API异常的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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()


当它在服务器上触发信用卡API时,却​​在本地完全正常,我收到上述错误.


错误出现在
:


I gets the above error when it fires the Credit card API on server while it works totally fine on local.


error comes at
:

// post data is sent as a stream
           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)
        {
            // By default, this sample code is designed to post to our test server for
            // developer accounts: https://test.authorize.net/gateway/transact.dll
            // for real accounts (even in test mode), please make sure that you are
            // posting to: https://secure.authorize.net/gateway/transact.dll
            String post_url = "https://test.authorize.net/gateway/transact.dll";

            Dictionary<string, string> post_values = new Dictionary<string, string>();
            //the API Login ID and Transaction Key must be replaced with valid values
            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");
            // Additional fields can be added here as outlined in the AIM integration
            // guide at: http://developer.authorize.net

            // This section takes the input fields and converts them to the proper format
            // for an http post.  For example: "x_login=username&x_tran_key=a1B2c3D4"
            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(''&'');

            // The following section provides an example of how to add line item details to
            // the post string.  Because line items may consist of multiple values with the
            // same key/name, they cannot be simply added into the above array.
            //
            // This section is commented out by default.
            /*
            string[] line_items = {
                "item1<|>golf balls<|><|>2<|>18.95<|>Y",
                "item2<|>golf bag<|>Wilson golf carry bag, red<|>1<|>39.99<|>Y",
                "item3<|>book<|>Golf for Dummies<|>1<|>21.99<|>Y"};
	
            foreach( string value in line_items )
            {
                post_string += "&x_line_item=" + HttpUtility.UrlEncode(value);
            }
            */

            // create an HttpWebRequest object to communicate with Authorize.net
            HttpWebRequest objRequest = (HttpWebRequest)WebRequest.Create(post_url);
            objRequest.Method = "POST";
            objRequest.ContentLength = post_string.Length;
            objRequest.ContentType = "application/x-www-form-urlencoded";

            // post data is sent as a stream
            StreamWriter myWriter  = null;
            myWriter = new StreamWriter(objRequest.GetRequestStream());
            myWriter.Write(post_string);
            myWriter.Close();

            // returned values are returned as a stream, then read into a string
            String post_response;
            HttpWebResponse objResponse = (HttpWebResponse)objRequest.GetResponse();
            using (StreamReader responseStream = new StreamReader(objResponse.GetResponseStream()) )
            {
                post_response = responseStream.ReadToEnd();
                responseStream.Close();
            }

            // the response string is broken into an array
            // The split character specified here must match the delimiting character specified above
            Array response_array = post_response.Split(''|'');

            // the results are output to the screen in the form of an html numbered list.
            resultSpan.InnerHtml += "<OL> \n";
            foreach (string value in response_array)
            {
                resultSpan.InnerHtml += "<LI>" + value + "&nbsp;</LI> \n";
            }
            resultSpan.InnerHtml += "</OL> \n";
            // individual elements of the array could be accessed to read certain response
            // fields.  For example, response_array[0] would return the Response Code,
            // response_array[2] would return the Response Reason Code.
            // for a list of response fields, please review the AIM Implementation Guide
        }

推荐答案

我遇到了同样的问题.您要在SSL上部署网站吗?

authorize.net API通过特定端口进行通信(您需要找到此端口),并且服务器上的端口默认情况下处于阻止状态.

找到端口后,您可以要求系统管理员为您打开该端口.
I had the same problem.Are you deploying the site on SSL ?

The authorize.net APIs communicate via a specific port ( you need to find this out) and the ports on the server are blocked by default.

Once you find out the port, you can ask your system administrator to open this port for you.


这篇关于服务器上的信用卡API异常的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆