请问使用这个类能在 请求头里面 加进Cookie吗?
一下是MSDN里的代码           string uriString;
Console.Write("\nPlease enter the URI to post data to {for example, http://www.contoso.com} : ");
uriString = Console.ReadLine(); // Create a new WebClient instance.
WebClient myWebClient = new WebClient();
Console.WriteLine("\nPlease enter the data to be posted to the URI {0}:",uriString);
string postData = Console.ReadLine();
myWebClient.Headers.Add("Content-Type","application/x-www-form-urlencoded");      // Display the headers in the request
Console.Write("Resulting Request Headers: ");
Console.WriteLine(myWebClient.Headers.ToString());

// Apply ASCII Encoding to obtain the string as a byte array. byte[] byteArray = Encoding.ASCII.GetBytes(postData);
Console.WriteLine("Uploading to {0} ...",  uriString);
// Upload the input string using the HTTP 1.0 POST method.
byte[] responseArray = myWebClient.UploadData(uriString,"POST",byteArray);

// Decode and display the response.
Console.WriteLine("\nResponse received was {0}",
        Encoding.ASCII.GetString(responseArray));
如果我要提交cooike 怎么办? 因为是要把图片下载下来,所以必须使用webclient这个类
UploadData这个函数一定要发送byteArray,那我只发送HTTP请求不需要POST什么东西该怎么办呢?

解决方案 »

  1.   

    http://topic.csdn.net/t/20050413/14/3933091.html
      

  2.   


    如果你有这个需求的话,就不应该用WebClient的,你应该用 HttpRequest
      

  3.   

    webclient和httprequest有啥区别?
      

  4.   


    HttpRequest 可以在请求时加Cookies,具体有什么区别,你还是baidu吧
      

  5.   

    WebClient command = new WebClient();
    command.Headers.Add("Cookie", cookie);
    你朋友不是一样使用这个类提交吗?
      

  6.   

    用httpresponse请求 加上cookeicontenner
      

  7.   

    WebClient很简单的,没有这么高级的功能,要这些功能就要用HttpWebRequest。
      

  8.   

    上面两个朋友 你能告诉我 HttpWebRequest 能下载图片 或者文件吗?有 我就不会起想WEBCLIENT的事!
      

  9.   

                string URL = "http://img5.immage.de/26056726970060.jpg";
                HttpWebRequest request = WebRequest.Create(URL) as HttpWebRequest;
                request.Method = "GET";
                request.KeepAlive = true;              
                //接收传来的值
                HttpWebResponse response = request.GetResponse() as HttpWebResponse;
                Stream responseStream = response.GetResponseStream();
                Bitmap OldBitmap = Image.FromStream(responseStream) as Bitmap;
                OldBitmap.Save("c:\\button.jpg", System.Drawing.Imaging.ImageFormat.Jpeg);问题自己解决了,大家有兴趣运行下这段代码!