Send XML via HTTP Post to IP:Port

后端 未结 2 796
鱼传尺愫
鱼传尺愫 2021-02-10 12:03

Ok so to start off, I\'m not using any sort of web service. Right now I don\'t know a whole lot about the application receiving the XML other than it receives it. Big help there

2条回答
  •  盖世英雄少女心
    2021-02-10 12:29

    The recommended way to make simple web requests is to use the WebClient object.

    Here's a code snippet:

    // assume your XML string is returned from GetXmlString()
    string xml = GetXmlString();
    
    
    // assume port 8080
    string url = new UriBuilder("http","www.example.com",8080).ToString();     
    
    
    // create a client object
    using(System.Net.WebClient client = new System.Net.WebClient()) {
        // performs an HTTP POST
        client.UploadString(url, xml);  
    
    }
    

提交回复
热议问题