Thread: HTTP Post Question

  1. #1
    Registered User penney's Avatar
    Join Date
    Jan 2003
    Posts
    47

    HTTP Post Question

    I wrote some code in VB to send XML to a HTTP server. I am including that code below. I confess that I do not know C# but I have a customer who is asking if we would know how to do what I did in VB in C#. Below is the VB code can someone please provide the C# equivalent if it's not too involved. Thank you very much:

    Code:
        Dim oWinhttp As New WinHttpRequest 
        Dim sResponse 
        
        'sXML is a string containing your XML to submit 
        With oWinhttp 
            Call .Open("POST", " https://emkt.pjm.com/emkt/xml/submit ") 
            Call .SetCredentials("your_user_name", "your_password", 0) 
            Call .SetRequestHeader("POST", "/emkt/xml/submit HTTP/1.1") 
            Call .SetRequestHeader("HOST", "emkt.pjm.com") 
            Call .SetRequestHeader("Content-Type", "text/xml") 
            Call .SetRequestHeader("Content-Length", Len(sXML)) 
            Call .SetRequestHeader("SOAPAction", "/emkt/xml/submit") 
            Call .Send(sXML) 
            'Wait for the response. 
            Call .WaitForResponse 
    
            'Display the response text. 
            sResponse = .ResponseText 
        End With

  2. #2
    Yes, my avatar is stolen anonytmouse's Avatar
    Join Date
    Dec 2002
    Posts
    2,544
    I don't think C# has the With keyword so something like:
    Code:
        WinHttpRequest oWinhttp = new WinHttpRequest;
        String sResponse;
        
        // sXML is a string containing your XML to submit 
        oWinhttp.Open("POST", " https://emkt.pjm.com/emkt/xml/submit ");
        oWinhttp.SetCredentials("your_user_name", "your_password", 0);
        oWinhttp.SetRequestHeader("POST", "/emkt/xml/submit HTTP/1.1"); 
        oWinhttp.SetRequestHeader("HOST", "emkt.pjm.com");
        oWinhttp.SetRequestHeader("Content-Type", "text/xml");
        oWinhttp.SetRequestHeader("Content-Length", sXML.Length); 
        oWinhttp.SetRequestHeader("SOAPAction", "/emkt/xml/submit");
        oWinhttp.Send(sXML);
        // Wait for the response. 
        oWinhttp.WaitForResponse();
    
        // Display the response text. 
        sResponse = oWinhttp.ResponseText;

  3. #3
    Registered User penney's Avatar
    Join Date
    Jan 2003
    Posts
    47
    Thank you!

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Replies: 21
    Last Post: 04-21-2009, 11:04 AM
  2. New compiler - Weird errors -,-.
    By Blackroot in forum C++ Programming
    Replies: 8
    Last Post: 08-27-2006, 07:23 AM
  3. another exercise question
    By luigi40 in forum C# Programming
    Replies: 3
    Last Post: 11-28-2005, 03:52 PM
  4. Writing all HTTP requests from a website to a log file
    By goomyman in forum C# Programming
    Replies: 1
    Last Post: 07-29-2005, 09:18 AM
  5. HTTP question
    By Sang-drax in forum A Brief History of Cprogramming.com
    Replies: 3
    Last Post: 11-06-2002, 06:27 PM