POSTing to another server

V

VK

Hello:

Having some issues with HttpWebRequest and HttpWebResponse.

1. We migrated from ASP to ASP.Net
2. We have a third party company, a credit processing company which
integrates with our web site. Working fine with ASP, since CC company
requires "name-value" pairs in form which is POST method only.
3. Trying the same with ASP.Net but with no luck.

CODE
==
dim strVariables as string
strVariables = "myvariables to be passed to cc company like -
amount=300&description=testing"

Dim httpwreq As HttpWebRequest =
CType(WebRequest.Create(https://www.cccompany.com/), HttpWebRequest)
httpwreq.Method = "POST"
httpwreq.ContentType = "application/x-www-form-urlencode"
httpwreq.ContentLength = strVariables.Length

Dim myWriter As StreamWriter
Try
myWriter = New StreamWriter(httpwreq.GetRequestStream)
myWriter.Write(strVariables)
Catch ex As Exception
Response.Write(ex.ToString)
Response.Write(ex.Source)
End Try

Dim httpwresp As HttpWebResponse = CType(httpwreq.GetResponse,
HttpWebResponse)
Dim sr As StreamReader
Dim result As String = ""

sr = New StreamReader(httpwresp.GetResponseStream())
result = sr.ReadToEnd()
sr.Close()
httpwresp.Close()
Response.Redirect(https://www.cccompany.com/)

==

Is something amiss above?

thanks.
 
P

Patrice

What is the behavior you see ?

1) System.Net.WebClient has an UploadValues method to which you just have to
pass a collection of name, value pairs...

2) Else you could dump what is received server side for comparison would a
usual post. It should allow to easily spot the difference (if I remember you
need a carriage return or something like that)
 
V

VK

It just times out

I am trying to post to another server in the form of name-value pairs,
don't need back any response from the other server.

Any ideas is appreciated!

Thanks.
Vani
 
J

Joerg Jooss

Thus wrote VK,
It just times out

I am trying to post to another server in the form of name-value pairs,
don't need back any response from the other server.

You need a response -- how else will you know if the request succeeded?

Anyway, in your case WebClient.UploadValues() will do the trick. You probably
need to add a User-Agent header in case the web application checks the browser
type.

Cheers,
 
P

Patrice

Have you tried one of these suggestions ?

Also if you don"t post for now to a page that is under your control, post
for now on such a page. It will be easier to see for example if the page is
reached...
 
V

VK

I am trying the Uploadvalue method.

While posting to the other server, I need to user to be transfered to
the other server to complete the form he was filling out and eventually
receive the recipt for his transaction, and all this done by the third
party company.

Will the above method redirect/transfer the user to the other web site?


Thanks so much.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top