cancel
Showing results for 
Search instead for 
Did you mean: 

Sample AIM VB.Net code failing -- error message "A connection attempt failed"

All -- I do not seem to be able to get ANY of the sample code working against the test or live systems, and am confused what the problem may be. (Note -- very new to web developing).

 

Specific error message with VB.NET sample code (changed API login id & transaction key):

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 64.94.118.33:443

 

[SocketException (0x274c): 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 64.94.118.33:443]
   System.Net.Sockets.Socket.DoConnect(EndPoint endPointSnapshot, SocketAddress socketAddress) +239
   System.Net.Sockets.Socket.InternalConnect(EndPoint remoteEP) +35
   System.Net.ServicePoint.ConnectSocketInternal(Boolean connectFailure, Socket s4, Socket s6, Socket& socket, IPAddress& address, ConnectSocketState state, IAsyncResult asyncResult, Int32 timeout, Exception& exception) +224

[WebException: Unable to connect to the remote server]
   System.Net.HttpWebRequest.GetRequestStream(TransportContext& context) +1872977
   System.Net.HttpWebRequest.GetRequestStream() +13
   races2run_test_auth.Button1_Click(Object sender, EventArgs e) +840
   System.Web.UI.WebControls.Button.OnClick(EventArgs e) +111
   System.Web.UI.WebControls.Button.RaisePostBackEvent(String eventArgument) +110
   System.Web.UI.WebControls.Button.System.Web.UI.IPostBackEventHandler.RaisePostBackEvent(String eventArgument) +10
   System.Web.UI.Page.RaisePostBackEvent(IPostBackEventHandler sourceControl, String eventArgument) +13
   System.Web.UI.Page.RaisePostBackEvent(NameValueCollection postData) +36
   System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint) +1565


 

I saw somewhere in the forum that someone had a similar issue and that it might be SSL related.  My SSL seems ok if you go to https://sitename.com, but if you go to www.sitename.com, you will get a SSL warning.  Could this be the issue?

Mike_reph
Member
1 ACCEPTED SOLUTION

Accepted Solutions

So, the solution to my problem is:

 

change the web.config file to add the proxy server for 1and1.com

 

<system.net>

      <defaultProxy>
        <proxy usesystemdefault="False"
        bypassonlocal="False"
        proxyaddress="http://ntproxy.1and1.com:3128"
/>
      </defaultProxy>

</system.net>

 

Thank you to Raynor for the research and finding the solution.

View solution in original post

11 REPLIES 11

Note -- I'm using a subdomain with SSL, but the top level domain is not secured by ssl...

Mike_reph
Member

That IP 64.94.118.33 is secure.authorize.net

Can you get to https://secure.authorize.net/ in a broswer?

Yes, I can access the https://secure.authorize.net/.    I'm wondering if https://secure.authorize.net/gateway/transact.dll is rejecting my connection because of how I have SSL set up.

 

I had (changing this now), SSL set up the following way (which is probably stupid, which is why I'm fixing it).

 

https://races2run.signup2raceusa.com had the SSL certificate

 

www.signup2raceusa.com was NOT secured via SSL.   

 

So I'm switching the SSL certificate to the root level domain instead of being in the subdomain.  Will test again tomorrow to see if that works.

Still not working.  Called Authorize.net support, and am very sad to say that they were almost no help at all.

Can you post your code, since it look like you make changes to the sample AIM VB code.

Just make sure you remove your loginID and transactionKey when you post.

Check if your firewall might be blocking it.

Could be the user on the IIS application pool don't have enough permission

Did the IIS log show anything?

 

Try do the

myWriter = New StreamWriter(objRequest.GetRequestStream())

to another URL like "http://www.yahoo.com" see if it still error on the same place

if that work try

"https://login.yahoo.com/"

 

My code below:

 Protected Sub Button1_Click(sender As Object, e As System.EventArgs) Handles Button1.Click
        ' 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

        Dim post_url As String
        post_url = "https://secure.authorize.net/gateway/transact.dll"

        Dim post_values As New Dictionary(Of String, String)
       
        post_values.Add("x_login", "my_login)
        post_values.Add("x_tran_key", "my_trankey")
        post_values.Add("x_test_request", "TRUE")
        post_values.Add("x_version", "3.0")
        post_values.Add("x_type", "AUTH_CAPTURE")
        post_values.Add("x_delim_data", "TRUE")
        post_values.Add("x_delim_char", "|")
        post_values.Add("x_relay_response", "FALSE")
        post_values.Add("x_method", "CC")
        'CUSTOMER INFO
        post_values.Add("x_card_num", "4111111111111111")
        post_values.Add("x_exp_date", "1220")

        post_values.Add("x_amount", "0.01")
        post_values.Add("x_description", "Test Purchase")

        post_values.Add("x_first_name", "John")
        post_values.Add("x_last_name", "Doe")
        post_values.Add("x_address", "1 Main 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"
        Dim post_string As String = ""
        For Each field As KeyValuePair(Of String, String) In post_values
            post_string &= field.Key & "=" & HttpUtility.UrlEncode(field.Value) & "&"
        Next
        post_string = Left(post_string, Len(post_string) - 1)
        Response.Write(post_string)

        ' 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.
        'Dim line_items() As String = { _
        '    "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"}
        '
        'For Each value As String In line_items
        '   post_string += "&x_line_item=" + HttpUtility.UrlEncode(value)
        'Next

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

        ' post data is sent as a stream
        Dim myWriter As StreamWriter = Nothing
        myWriter = New StreamWriter(objRequest.GetRequestStream())
        myWriter.Write(post_string)
        myWriter.Close()

        ' returned values are returned as a stream, then read into a string
        Dim objResponse As HttpWebResponse = CType(objRequest.GetResponse(), HttpWebResponse)
        Dim responseStream As New StreamReader(objResponse.GetResponseStream())
        Dim post_response As String = responseStream.ReadToEnd()
        responseStream.Close()

        ' the response string is broken into an array
        Dim response_array As Array = Split(post_response, post_values("x_delim_char"), -1)

            Dim i As Integer = 0
        'For Each value In response_array
        ' i += 1 '(shorthand for i = i + 1)
        ' Response.Write(i & ") " & value & "<br />" & vbCrLf)
        'Next
        ' 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
    End Sub

Hi Raynor,

 

I think you are on to something.   I tried the same code, but changed the url to "http://www.yahoo.com" and received the exact same error message...

 

I am using hosting from 1&1.com, and am engaged with their support folks.  I'm suspecting that it might be a rights issue...

Did some research on my lunch break.

Read the section on Communicating with PayPal Server via a Proxy Server

http://tofuculture.com/Blog/post/Tips-Tricks-of-Using-11-Shared-Hosting-Environment.aspx

 

and proxy server config for 1&1

http://www.cyberslingers.com/weblog/post/Parse-ATOM-with-ASPNET.aspx