C# WebClient OpenWrite(Uri, String)

Description

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

Syntax

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


public Stream OpenWrite(
  Uri address,
  string method
)

Parameters

WebClient.OpenWrite(Uri, 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(Uri, String) method returns A Stream used to write data to the resource.

Example


/*from  w  w  w.  j a  v  a2 s  . co 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(new Uri(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