Solved

vb script to C#

Posted on 2011-02-21
7
372 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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:Praveen Kumar
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
Salesforce Made Easy to Use

On-screen guidance at the moment of need enables you & your employees to focus on the core, you can now boost your adoption rates swiftly and simply with one easy tool.

 
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

PeopleSoft Has Never Been Easier

PeopleSoft Adoption Made Smooth & Simple!

On-The-Job Training Is made Intuitive & Easy With WalkMe's On-Screen Guidance Tool.  Claim Your Free WalkMe Account Now

Question has a verified solution.

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

This article describes a simple method to resize a control at runtime.  It includes ready-to-use source code and a complete sample demonstration application.  We'll also talk about C# Extension Methods. Introduction In one of my applications…
Introduction Hi all and welcome to my first article on Experts Exchange. A while ago, someone asked me if i could do some tutorials on object oriented programming. I decided to do them on C#. Now you may ask me, why's that? Well, one of the re…
Michael from AdRem Software outlines event notifications and Automatic Corrective Actions in network monitoring. Automatic Corrective Actions are scripts, which can automatically run upon discovery of a certain undesirable condition in your network.…
Do you want to know how to make a graph with Microsoft Access? First, create a query with the data for the chart. Then make a blank form and add a chart control. This video also shows how to change what data is displayed on the graph as well as form…

635 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