Solved

vb script to C#

Posted on 2011-02-21
7
370 Views
Last Modified: 2012-05-11
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
Comment
Question by:ube100
  • 3
  • 3
7 Comments
 
LVL 52

Expert Comment

by:Carl Tawn
ID: 34941716
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
 
LVL 12

Expert Comment

by:Mamtha1982
ID: 34941738
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
 

Author Comment

by:ube100
ID: 34946347
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
Netscaler Common Configuration How To guides

If you use NetScaler you will want to see these guides. The NetScaler How To Guides show administrators how to get NetScaler up and configured by providing instructions for common scenarios and some not so common ones.

 
LVL 52

Expert Comment

by:Carl Tawn
ID: 34946412
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
 

Author Comment

by:ube100
ID: 34946632
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
 
LVL 52

Accepted Solution

by:
Carl Tawn earned 250 total points
ID: 34946674
You need to add the line:
req.Method = "POST";

Open in new window

Just after you set the ContentType property.
0
 

Author Closing Comment

by:ube100
ID: 34947124
Thanx!!!
0

Featured Post

Best Practices: Disaster Recovery Testing

Besides backup, any IT division should have a disaster recovery plan. You will find a few tips below relating to the development of such a plan and to what issues one should pay special attention in the course of backup planning.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

It’s quite interesting for me as I worked with Excel using vb.net for some time. Here are some topics which I know want to share with others whom this might help. First of all if you are working with Excel then you need to Download the Following …
Parsing a CSV file is a task that we are confronted with regularly, and although there are a vast number of means to do this, as a newbie, the field can be confusing and the tools can seem complex. A simple solution to parsing a customized CSV fi…
In a recent question (https://www.experts-exchange.com/questions/28997919/Pagination-in-Adobe-Acrobat.html) here at Experts Exchange, a member asked how to add page numbers to a PDF file using Adobe Acrobat XI Pro. This short video Micro Tutorial sh…
Established in 1997, Technology Architects has become one of the most reputable technology solutions companies in the country. TA have been providing businesses with cost effective state-of-the-art solutions and unparalleled service that is designed…

831 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question