C# WebClient OpenWrite(String, String)

Description

WebClient OpenWrite(String, String) Opens a stream for writing data to the specified resource, using the specified method.

Syntax

WebClient.OpenWrite(String, String) has the following syntax.


public Stream OpenWrite(
  string address,
  string method
)

Parameters

WebClient.OpenWrite(String, String) has the following parameters.

  • address - The URI of the resource to receive the data.
  • method - The method used to send the data to the resource. If null, the default is POST for http and STOR for ftp.

Returns

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

Example

The following code example uses OpenWrite to obtain a stream used to write the data.


/*  w  w  w . j  a v  a  2 s  .c  o  m*/
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://your server";
        string postData = "data";
        byte[] postArray = Encoding.ASCII.GetBytes(postData);
        WebClient myWebClient = new WebClient();

        Stream postStream = myWebClient.OpenWrite(uriString, "POST");
        postStream.Write(postArray, 0, postArray.Length);

        postStream.Close();
        Console.WriteLine("\nSuccessfully posted the data.");

    }
}




















Home »
  C# Tutorial »
    System.Net »




Cookie
Dns
IPAddress
IPEndPoint
IPHostEntry
WebClient