Solved

I want to Help vb convert to c#

Posted on 2007-11-14
2
203 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
Comment Utility
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
Comment Utility
thanks
0

Featured Post

Why You Should Analyze Threat Actor TTPs

After years of analyzing threat actor behavior, it’s become clear that at any given time there are specific tactics, techniques, and procedures (TTPs) that are particularly prevalent. By analyzing and understanding these TTPs, you can dramatically enhance your security program.

Join & Write a Comment

IntroductionWhile developing web applications, a single page might contain many regions and each region might contain many number of controls with the capability to perform  postback. Many times you might need to perform some action on an ASP.NET po…
Introduction This article shows how to use the open source plupload control to upload multiple images. The images are resized on the client side before uploading and the upload is done in chunks. Background I had to provide a way for user…
In this seventh video of the Xpdf series, we discuss and demonstrate the PDFfonts utility, which lists all the fonts used in a PDF file. It does this via a command line interface, making it suitable for use in programs, scripts, batch files — any pl…
This demo shows you how to set up the containerized NetScaler CPX with NetScaler Management and Analytics System in a non-routable Mesos/Marathon environment for use with Micro-Services applications.

763 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

9 Experts available now in Live!

Get 1:1 Help Now