Home All Groups Group Topic Archive Search About

POST request frow windows app??

Author
6 Aug 2006 5:19 AM
Brad
I'm in the processing of upgrading some VBA code that sends a POST-AUTH
request to a secure server (credit card authorization to a payment
gateway)  then parses the return.  I'm trying to figure out how to do
this with VB 2005 Windows App.

Old Code example:
'Get ready to send request to gateway
WinHttpReq.Open("POST", "https://***URLTOSECURESERVER**", False)
WinHttpReq.SetRequestHeader("Content-Type",
"application/x-www-form-urlencoded")
WinHttpReq.Send(strPostString)
lStatusCode = WinHttpReq.Status
lsReturn = WinHttpReq.ResponseText

How to do the same thing in .net?

Author
6 Aug 2006 2:38 PM
Carl Daniel [VC++ MVP]
Brad wrote:
Show quote
> I'm in the processing of upgrading some VBA code that sends a
> POST-AUTH request to a secure server (credit card authorization to a
> payment gateway)  then parses the return.  I'm trying to figure out
> how to do this with VB 2005 Windows App.
>
> Old Code example:
> 'Get ready to send request to gateway
> WinHttpReq.Open("POST", "https://***URLTOSECURESERVER**", False)
> WinHttpReq.SetRequestHeader("Content-Type",
> "application/x-www-form-urlencoded")
> WinHttpReq.Send(strPostString)
> lStatusCode = WinHttpReq.Status
> lsReturn = WinHttpReq.ResponseText
>
> How to do the same thing in .net?

See the System.Net.HttpWebRequest class.  The method names, properties, etc,
are nearly the same - you should have no trouble translating.

-cd
Author
6 Aug 2006 6:35 PM
Brad
Ok, I got that to post.  Now, my next problem is getting back all of
the server response. I can't seem to get all of the data from the
response.  How can I get back the response and parse out the
information?

Old code:
lStatusCode = WinHttpReq.Status
lsReturn = WinHttpReq.ResponseText
'parse the return values
lasReturn = Split(lsReturn, "&")
For i = 0 To UBound(lasReturn)
   lasKeyPair = Split(lasReturn(i), "=")
      Select Case LCase(lasKeyPair(0))
           Case "responsecode"
              lsResponseCode = lasKeyPair(1)
              Case "responsemessage"
              lsResponseMessage = lasKeyPair(1)
           Case "transactionid"
              lsTransactionID = lasKeyPair(1)
           Case "avsresponse"
              lsAVSResponse = lasKeyPair(1)
           Case "cvv2response"
              lsCVV2Response = lasKeyPair(1)
           Case "authcode"
              lsAuthCode = lasKeyPair(1)
      End Select

Carl Daniel [VC++ MVP] wrote:
Show quote
> Brad wrote:
> > I'm in the processing of upgrading some VBA code that sends a
> > POST-AUTH request to a secure server (credit card authorization to a
> > payment gateway)  then parses the return.  I'm trying to figure out
> > how to do this with VB 2005 Windows App.
> >
> > Old Code example:
> > 'Get ready to send request to gateway
> > WinHttpReq.Open("POST", "https://***URLTOSECURESERVER**", False)
> > WinHttpReq.SetRequestHeader("Content-Type",
> > "application/x-www-form-urlencoded")
> > WinHttpReq.Send(strPostString)
> > lStatusCode = WinHttpReq.Status
> > lsReturn = WinHttpReq.ResponseText
> >
> > How to do the same thing in .net?
>
> See the System.Net.HttpWebRequest class.  The method names, properties, etc,
> are nearly the same - you should have no trouble translating.
>
> -cd
Author
6 Aug 2006 8:50 PM
Carl Daniel [VC++ MVP]
Brad wrote:
> Ok, I got that to post.  Now, my next problem is getting back all of
> the server response. I can't seem to get all of the data from the
> response.  How can I get back the response and parse out the
> information?

What are you trying?  Typically, you'll call
HttpWebResponse.GetResponseStream() and read the response line by line, or
all at once, however you wish.

-cd

AddThis Social Bookmark Button