Solved

I want to Help vb convert to c#

Posted on 2007-11-14
2
206 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: 20287287
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: 20310408
thanks
0

Featured Post

3 Use Cases for Connected Systems

Our Dev teams are like yours. They’re continually cranking out code for new features/bugs fixes, testing, deploying, testing some more, responding to production monitoring events and more. It’s complex. So, we thought you’d like to see what’s working for us.

Question has a verified solution.

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

For those of you who don't follow the news, or just happen to live under rocks, Microsoft Research released a beta SDK (http://www.microsoft.com/en-us/download/details.aspx?id=27876) for the Xbox 360 Kinect. If you don't know what a Kinect is (http:…
A long time ago (May 2011), I have written an article showing you how to create a DLL using Visual Studio 2005 to be hosted in SQL Server 2005. That was valid at that time and it is still valid if you are still using these versions. You can still re…
Video by: Mark
This lesson goes over how to construct ordered and unordered lists and how to create hyperlinks.
Learn how to create flexible layouts using relative units in CSS.  New relative units added in CSS3 include vw(viewports width), vh(viewports height), vmin(minimum of viewports height and width), and vmax (maximum of viewports height and width).

920 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