• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 378
  • Last Modified:

vb script to C#

Hi, Can somebody help me converting this VB script into C# please:

Dim sResponse
Dim oHTTP

 Set oHTTP = CreateObject("MSXML2.XMLHTTP")

oHttp.Open "POST", "http://secure.voice-pay.com/gateway/remote_auth", False
oHttp.SetRequestHeader "Content-Type", "application/x-www-form-urlencoded"
oHttp.Send sRequestString

sResponse  = oHttp.responseText
0
ube100
Asked:
ube100
  • 3
  • 3
1 Solution
 
Carl TawnSystems and Integration DeveloperCommented:
Try this:
            HttpWebRequest req = (HttpWebRequest)WebRequest.Create("http://secure.voice-pay.com/gateway.remote_auth");
            req.ContentType = "application/x-www-form-urlencoded";

            HttpWebResponse resp = (HttpWebResponse)req.GetResponse();
            string result;
            using (System.IO.StreamReader reader = new System.IO.StreamReader(resp.GetResponseStream()))
            {
                result = reader.ReadToEnd();
            }

Open in new window

0
 
Praveen KumarArchitectCommented:
Alternative you can use HttpRequest class in c#:

HttpWebRequest wr = (HttpWebRequest)WebRequest.Create("http://secure.voice-pay.com/gateway/remote_auth");

HttpWebResponse rs = (HttpWebResponse)wr.GetResponse();
Stream s = rs.GetResponseStream();
StreamReader srt = new StreamReader(s);
receiveData = srt.ReadToEnd();

0
 
ube100Author Commented:
Guys,

How do I set the request string?

oHttp.Send sRequestString

As you can see I'm setting the request string on the above line but in your C# code there is nothing there.
0
Independent Software Vendors: 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!

 
Carl TawnSystems and Integration DeveloperCommented:
You need to grab the RequestStream and write your data to it:
            HttpWebRequest req = (HttpWebRequest)WebRequest.Create("http://secure.voice-pay.com/gateway.remote_auth");
            req.ContentType = "application/x-www-form-urlencoded";

            using (System.IO.StreamWriter writer = new System.IO.StreamWriter(req.GetRequestStream()))
            {
                writer.Write(sRequestString);
            }

            HttpWebResponse resp = (HttpWebResponse)req.GetResponse();
            string result;
            using (System.IO.StreamReader reader = new System.IO.StreamReader(resp.GetResponseStream()))
            {
                result = reader.ReadToEnd();
            }

Open in new window

0
 
ube100Author Commented:
On this line:

(System.IO.StreamWriter writer = new System.IO.StreamWriter(req.GetRequestStream()))

getting this error:

cannot send a content-body with this verb- type.
0
 
Carl TawnSystems and Integration DeveloperCommented:
You need to add the line:
req.Method = "POST";

Open in new window

Just after you set the ContentType property.
0
 
ube100Author Commented:
Thanx!!!
0

Featured Post

Hire Technology Freelancers with Gigs

Work with freelancers specializing in everything from database administration to programming, who have proven themselves as experts in their field. Hire the best, collaborate easily, pay securely, and get projects done right.

  • 3
  • 3
Tackle projects and never again get stuck behind a technical roadblock.
Join Now