Open a stream for writing data to the specified resource in CSharp

Description

The following code shows how to open a stream for writing data to the specified resource.

Example


using System;/* www. ja v  a  2s .c  o m*/
using System.Net;
using System.Net.Sockets;
using System.Text;
using System.IO;

public class Example
{
    public static void Main()
    {

        string uriString = "http://yourServer";
        string postData = "yourData";
        byte[] postArray = Encoding.ASCII.GetBytes(postData);
        WebClient myWebClient = new WebClient();
        Console.WriteLine("Uploading to {0} ...", uriString);
        Stream postStream = myWebClient.OpenWrite(uriString);

        postStream.Write(postArray, 0, postArray.Length);
        postStream.Close();

    }
}

The code above generates the following result.





















Home »
  C# Tutorial »
    Network »




IP
Web Client