Solved

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

Posted on 2007-11-14
2
256 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
[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
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

[Webinar] Code, Load, and Grow

Managing multiple websites, servers, applications, and security on a daily basis? Join us for a webinar on May 25th to learn how to simplify administration and management of virtual hosts for IT admins, create a secure environment, and deploy code more effectively and frequently.

Question has a verified solution.

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

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 article aims to explain the working of CircularLogArchiver. This tool was designed to solve the buildup of log file in cases where systems do not support circular logging or where circular logging is not enabled
Nobody understands Phishing better than an anti-spam company. That’s why we are providing Phishing Awareness Training to our customers. According to a report by Verizon, only 3% of targeted users report malicious emails to management. With compan…
Suggested Courses

739 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