Solved

Any one Help me I want to convert vb code  to c# code

Posted on 2007-11-14
2
242 Views
Last Modified: 2010-04-15
Function postData(astrUrlToPostTo, astrDataToPost)

        On Error GoTo TrapError

           
            Dim objXML
            Set objXML = CreateObject("MSXML2.ServerXMLHTTP")
           
            objXML.Open "POST", astrUrlToPostTo, False
            objXML.setRequestHeader "Content-Type", "application/x-www-form-urlencoded"
            objXML.setRequestHeader "Content-Length", Len(astrDataToPost)
            objXML.setTimeouts 120000, 120000, 120000, 120000
            objXML.send astrDataToPost
            If (objXML.Status = 200 And Err.Number = 0) Then
                postData = objXML.responseText
            Else
                postData = ""
            End If
        Call checkErrors("Error")
        Set objXML = Nothing
        Exit Function
TrapError:
        MsgBox Err.description
    End Function
0
Comment
Question by:sitg
2 Comments
 
LVL 9

Accepted Solution

by:
codeclay earned 500 total points
ID: 20287304
Try this...
private void postData(string astrUrlToPostTo,string astrDataToPost)
    {
        try
        {
            System.Net.HttpWebRequest req = (System.Net.HttpWebRequest)System.Net.WebRequest.Create(astrUrlToPostTo);
            req.Method = "POST";
            req.Timeout = 120000;
            req.Headers.Add(System.Net.HttpRequestHeader.ContentType, "application/x-www-form-urlencoded");
            req.Headers.Add(System.Net.HttpRequestHeader.ContentLength, astrDataToPost.Length.ToString());
            System.Net.HttpWebResponse res = (System.Net.HttpWebResponse)req.GetResponse();
            string result = "";
            if (res.StatusCode == System.Net.HttpStatusCode.OK)
            {
                System.IO.Stream iostream = res.GetResponseStream();
                System.Text.Encoding encoding = System.Text.Encoding.GetEncoding("utf-8");
                System.IO.StreamReader readStream = new System.IO.StreamReader(iostream, encoding);
                result = readStream.ReadToEnd();
            }
        }
        catch (Exception ex)
        {

        }
    }
0
 

Author Comment

by:sitg
ID: 20310399
thanks
0

Featured Post

IT, Stop Being Called Into Every Meeting

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

Join & Write a Comment

User art_snob (http://www.experts-exchange.com/M_6114203.html) encountered strange behavior of Android Web browser on his Mobile Web site. It took a while to find the true cause. It happens so, that the Android Web browser (at least up to OS ver. 2.…
It was really hard time for me to get the understanding of Delegates in C#. I went through many websites and articles but I found them very clumsy. After going through those sites, I noted down the points in a easy way so here I am sharing that unde…
This video gives you a great overview about bandwidth monitoring with SNMP and WMI with our network monitoring solution PRTG Network Monitor (https://www.paessler.com/prtg). If you're looking for how to monitor bandwidth using netflow or packet s…
This video shows how to remove a single email address from the Outlook 2010 Auto Suggestion memory. NOTE: For Outlook 2016 and 2013 perform the exact same steps. Open a new email: Click the New email button in Outlook. Start typing the address: …

705 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

Need Help in Real-Time?

Connect with top rated Experts

15 Experts available now in Live!

Get 1:1 Help Now