ube100
asked on
vb script to C#
Hi, Can somebody help me converting this VB script into C# please:
Dim sResponse
Dim oHTTP
Set oHTTP = CreateObject("MSXML2.XMLHT TP")
oHttp.Open "POST", "http://secure.voice-pay.com/gateway/remote_auth", False
oHttp.SetRequestHeader "Content-Type", "application/x-www-form-ur lencoded"
oHttp.Send sRequestString
sResponse = oHttp.responseText
Dim sResponse
Dim oHTTP
Set oHTTP = CreateObject("MSXML2.XMLHT
oHttp.Open "POST", "http://secure.voice-pay.com/gateway/remote_auth", False
oHttp.SetRequestHeader "Content-Type", "application/x-www-form-ur
oHttp.Send sRequestString
sResponse = oHttp.responseText
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.GetRes ponse();
Stream s = rs.GetResponseStream();
StreamReader srt = new StreamReader(s);
receiveData = srt.ReadToEnd();
HttpWebRequest wr = (HttpWebRequest)WebRequest
HttpWebResponse rs = (HttpWebResponse)wr.GetRes
Stream s = rs.GetResponseStream();
StreamReader srt = new StreamReader(s);
receiveData = srt.ReadToEnd();
ASKER
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.
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.
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();
}
ASKER
On this line:
(System.IO.StreamWriter writer = new System.IO.StreamWriter(req .GetReques tStream()) )
getting this error:
cannot send a content-body with this verb- type.
(System.IO.StreamWriter writer = new System.IO.StreamWriter(req
getting this error:
cannot send a content-body with this verb- type.
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Thanx!!!
Open in new window