C# WebClient OpenWrite(Uri)

Description

WebClient OpenWrite(Uri) Opens a stream for writing data to the specified resource.

Syntax

WebClient.OpenWrite(Uri) has the following syntax.


public Stream OpenWrite(
  Uri address
)

Parameters

WebClient.OpenWrite(Uri) has the following parameters.

  • address - The URI of the resource to receive the data.

Returns

WebClient.OpenWrite(Uri) method returns A Stream used to write data to the resource.

Example


//w  w w  .  ja v  a  2  s.c om
using System;
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(new Uri(uriString));

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

    }
}




















Home »
  C# Tutorial »
    System.Net »




Cookie
Dns
IPAddress
IPEndPoint
IPHostEntry
WebClient