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
ube100Asked:
Who is Participating?
 
Carl TawnConnect With a Mentor Systems and Integration DeveloperCommented:
You need to add the line:
req.Method = "POST";

Open in new window

Just after you set the ContentType property.
0
 
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
Cloud Class® Course: CompTIA Cloud+

The CompTIA Cloud+ Basic training course will teach you about cloud concepts and models, data storage, networking, and network infrastructure.

 
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
 
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
 
ube100Author Commented:
Thanx!!!
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.