C# WebClient UploadValues(Uri, String, NameValueCollection)

Description

WebClient UploadValues(Uri, String, NameValueCollection) Uploads the specified name/value collection to the resource identified by the specified URI, using the specified method.

Syntax

WebClient.UploadValues(Uri, String, NameValueCollection) has the following syntax.


public byte[] UploadValues(
  Uri address,//w  ww . j  ava2s  . co m
  string method,
  NameValueCollection data
)

Parameters

WebClient.UploadValues(Uri, String, NameValueCollection) has the following parameters.

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

Returns

WebClient.UploadValues(Uri, String, NameValueCollection) method returns

Example


//  w w w.j a  v  a  2s.c  om
using System;
using System.Net;
using System.Net.Sockets;
using System.Collections.Specialized;
using System.Text;

public class Example
{
    public static void Main()
    {

        string uriString = "http://your server";
        WebClient myWebClient = new WebClient();
        NameValueCollection myNameValueCollection = new NameValueCollection();
        string name = "HTML";
        string age = "23";
        string address = "W3C";
        myNameValueCollection.Add("Name", name);
        myNameValueCollection.Add("Address", address);
        myNameValueCollection.Add("Age", age);
        byte[] responseArray = myWebClient.UploadValues(new Uri(uriString), "POST", myNameValueCollection);

        Console.WriteLine("\nResponse received was :\n{0}", Encoding.ASCII.GetString(responseArray));

    }
}




















Home »
  C# Tutorial »
    System.Net »




Cookie
Dns
IPAddress
IPEndPoint
IPHostEntry
WebClient