Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

I want to Help vb convert to c#

Posted on 2007-11-14
2
Medium Priority
?
213 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 2000 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

Free Backup Tool for VMware and Hyper-V

Restore full virtual machine or individual guest files from 19 common file systems directly from the backup file. Schedule VM backups with PowerShell scripts. Set desired time, lean back and let the script to notify you via email upon completion.  

Question has a verified solution.

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

Problem Hi all,    While many today have fast Internet connection, there are many still who do not, or are connecting through devices with a slower connect, so light web pages and fast load times are still popular.    If your ASP.NET page …
Calculating holidays and working days is a function that is often needed yet it is not one found within the Framework. This article presents one approach to building a working-day calculator for use in .NET.
This course is ideal for IT System Administrators working with VMware vSphere and its associated products in their company infrastructure. This course teaches you how to install and maintain this virtualization technology to store data, prevent vuln…
Have you created a query with information for a calendar? ... and then, abra-cadabra, the calendar is done?! I am going to show you how to make that happen. Visualize your data!  ... really see it To use the code to create a calendar from a q…

688 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