[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Dotgnu-pnet-commits] CVS: pnetlib/System/Net WebClient.cs,1.2,1.3
From: |
Gopal.V <address@hidden> |
Subject: |
[Dotgnu-pnet-commits] CVS: pnetlib/System/Net WebClient.cs,1.2,1.3 |
Date: |
Mon, 26 May 2003 01:20:55 -0400 |
Update of /cvsroot/dotgnu-pnet/pnetlib/System/Net
In directory subversions:/tmp/cvs-serv4359/System/Net
Modified Files:
WebClient.cs
Log Message:
Use MIME headers for file uploads
Index: WebClient.cs
===================================================================
RCS file: /cvsroot/dotgnu-pnet/pnetlib/System/Net/WebClient.cs,v
retrieving revision 1.2
retrieving revision 1.3
diff -C2 -r1.2 -r1.3
*** WebClient.cs 25 May 2003 07:24:31 -0000 1.2
--- WebClient.cs 26 May 2003 05:20:53 -0000 1.3
***************
*** 23,26 ****
--- 23,27 ----
using System;
using System.IO;
+ using System.Text;
using System.ComponentModel;
using System.Collections.Specialized;
***************
*** 35,43 ****
private String baseAddress=null;
private void CreateWebrequest(String str)
{
if(str == null)
{
! throw new ArgumentNullException(str);
}
if(webrequest!=null)
--- 36,48 ----
private String baseAddress=null;
+ const String defaultContentType = "application/octet-stream";
+ const String fileContentType = "multipart/form-data";
+ const String formContentType =
"application/x-www-form-urlencoded";
+
private void CreateWebrequest(String str)
{
if(str == null)
{
! throw new ArgumentNullException("str");
}
if(webrequest!=null)
***************
*** 70,74 ****
}
}
!
public byte[] DownloadData(String address)
{
--- 75,79 ----
}
}
!
public byte[] DownloadData(String address)
{
***************
*** 115,120 ****
}
- /* TODO : someday I'm going to implement Chunked data sends
- this way */
public byte[] UploadData(String address, String method, byte[]
data)
{
--- 120,123 ----
***************
*** 122,125 ****
--- 125,129 ----
webrequest.Method = method;
webrequest.ContentLength = data.Length;
+ webrequest.ContentType = defaultContentType;
Stream stream = webrequest.GetRequestStream();
stream.Write(data,0,data.Length);
***************
*** 138,150 ****
return UploadFile(address, "POST", fileName);
}
!
public byte[] UploadFile(String address, String method, String
fileName)
{
CreateWebrequest(address);
webrequest.Method = method;
Stream file = File.OpenRead(fileName);
try
{
webrequest.ContentLength = file.Length;
}
catch
--- 142,172 ----
return UploadFile(address, "POST", fileName);
}
! /* Note: refer rfc2068.txt for more info */
public byte[] UploadFile(String address, String method, String
fileName)
{
+ String name=Path.GetFileName(fileName);
+ /* Some inane boundary not likely in a data stream
generally */
+ String mimeBoundary =
+
"--DotGNU--Portable--message--"+
+
DateTime.Now.Ticks.ToString("X");
+ byte [] boundary =
+ Encoding.ASCII.GetBytes("\r\n--" +
mimeBoundary + "\r\n");
+
+ String headerString =
+ "--"+boundary + "\r\n" +
+ "Content-Disposition: form-data;
name=\"file\";filename\""+name+"\""+"\r\n"
+ + "\r\n";
+
+ byte [] header = Encoding.UTF8.GetBytes(headerString);
+
CreateWebrequest(address);
webrequest.Method = method;
+ webrequest.ContentType = fileContentType + "; " +
+
"boundary="+mimeBoundary;
Stream file = File.OpenRead(fileName);
try
{
webrequest.ContentLength = file.Length;
+ webrequest.ContentLength +=
header.Length+boundary.Length;
}
catch
***************
*** 152,156 ****
}
Stream stream = webrequest.GetRequestStream();
! WriteToStream(file,stream, -1);
webresponse = webrequest.GetResponse();
MemoryStream memory = new MemoryStream(1024);
--- 174,184 ----
}
Stream stream = webrequest.GetRequestStream();
!
! // Send in the mime header
! stream.Write(header,0,header.Length);
! WriteToStream(file,stream,-1);
! // Send in the boundary
! stream.Write(boundary,0,boundary.Length);
!
webresponse = webrequest.GetResponse();
MemoryStream memory = new MemoryStream(1024);
[Prev in Thread] |
Current Thread |
[Next in Thread] |
- [Dotgnu-pnet-commits] CVS: pnetlib/System/Net WebClient.cs,1.2,1.3,
Gopal.V <address@hidden> <=
- Prev by Date:
[Dotgnu-pnet-commits] CVS: pnetlib ChangeLog,1.936,1.937
- Next by Date:
[Dotgnu-pnet-commits] CVS: pnet/engine null_coder.c,1.19,1.20 cvmc.c,1.38,1.39 cvmc_except.c,1.8,1.9 verify_except.c,1.8,1.9
- Previous by thread:
[Dotgnu-pnet-commits] CVS: pnetlib ChangeLog,1.936,1.937
- Next by thread:
[Dotgnu-pnet-commits] CVS: pnet/engine null_coder.c,1.19,1.20 cvmc.c,1.38,1.39 cvmc_except.c,1.8,1.9 verify_except.c,1.8,1.9
- Index(es):