?
Solved

NullReferenceException w/ authorize.net

Posted on 2004-08-30
5
Medium Priority
?
242 Views
Last Modified: 2013-11-29
getting a NullReferenceException error on this line: myWriter.Close();

in this code:

public static string CreditCardProcessorCaller(string[] arrCCData) {

string strResult = "";
string strPost = "x_login=" + "someuser" +
"&x_password=" + "somepassword" +
"&x_version=3.1" +
"&x_delim_data=TRUE" +
"&x_delim_char=|" +
"&x_method=CC" +
"&x_recurring_billing=NO" +
"&x_type=AUTH_CAPTURE" +
"&x_amount=5.00" +
"&x_card_num=" + arrCCData[0] +
"&x_exp_date=" + arrCCData[1] +
"&x_card_code=" + arrCCData[2] +
"&x_cust_id=" + arrCCData[3] +
"&x_customer_ip=" + arrCCData[4] +
"&x_first_name=" + arrCCData[5] +
"&x_last_name=" + arrCCData[6] +
"&x_address=" + arrCCData[7] +
"&x_city=" + arrCCData[8] +
"&x_state=" + arrCCData[9] +
"&x_zip=" + arrCCData[10];

StreamWriter myWriter = null;
HttpWebRequest objRequest = (HttpWebRequest)WebRequest.Create("https://security.authorize.net/gateway/transact.dll");
objRequest.Method = "POST";
objRequest.ContentLength = strPost.Length;
objRequest.ContentType = "application/x-www-form-urlencoded";

try
{
myWriter = new StreamWriter(objRequest.GetRequestStream());
myWriter.Write(strPost);
}
catch (Exception strException)
{
return strException.ToString();
}
finally
{
myWriter.Close();
}

HttpWebResponse objResponse = (HttpWebResponse)objRequest.GetResponse();
using (StreamReader sr = new StreamReader(objResponse.GetResponseStream()))
{
strResult = sr.ReadToEnd();
sr.Close();
}

return strResult;
}
0
Comment
Question by:loyaliser
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
5 Comments
 
LVL 33

Expert Comment

by:raterus
ID: 11933900
I'd have to say that this line is failing in the first place..
myWriter = new StreamWriter(objRequest.GetRequestStream());

if myWriter can't be instantiated, it surely can't be closed!
0
 
LVL 1

Author Comment

by:loyaliser
ID: 11934037
actually, just figured it out... typo... sending to the wrong URL:

("https://security.authorize.net/gateway/transact.dll");

should be:

("https://secure.authorize.net/gateway/transact.dll");
0
 
LVL 10

Expert Comment

by:jnhorst
ID: 11934580
Also, if the fixed URL does not solve the problem, I think you should change:

HttpWebRequest objRequest = (HttpWebRequest)WebRequest.Create({url});

to:

WebRequest req = HttpWebRequest.Create({url});

Johhn
0
 
LVL 1

Accepted Solution

by:
Computer101 earned 0 total points
ID: 12185365
PAQed, with points refunded (500)

Computer101
E-E Admin
0

Featured Post

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

SSL stands for “Secure Sockets Layer” and an SSL certificate is a critical component to keeping your website safe, secured, and compliant. Any ecommerce website must have an SSL certificate to ensure the safe handling of sensitive information like…
Every business owner understands the significance of online customer reviews and the impact it can have on sales and revenues. With technology advancing at such a rapid pace, getting online reviews has never been easier, especially when many regions…
This tutorial demonstrates a quick way of adding group price to multiple Magento products.
You have products, that come in variants and want to set different prices for them? Watch this micro tutorial that describes how to configure prices for Magento super attributes. Assigning simple products to configurable: We assigned simple products…
Suggested Courses

752 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question