500分请教模拟WEB文件自动上传功能,答对可以分几次给。

christ2 2008-05-07 04:33:58
现在想在程序上实现在对某个WEB页面提交一组数据,其中包括文件上传。有点像爬虫,只不过爬虫是抓数据,而该程序是提交数据。

我现在还不知道能不能实现,如果不能,给个理由,本贴分数[100]全部提供。
...全文
115 16 打赏 收藏 转发到动态 举报
写回复
用AI写文章
16 条回复
切换为时间正序
请发表友善的回复…
发表回复
christ2 2008-05-13
  • 打赏
  • 举报
回复
没人回答出来,平分吧。
家鸣 2008-05-09
  • 打赏
  • 举报
回复
反编译UploadFile,看看它怎么生成request流
public byte[] UploadFile(string address, string method, string fileName)
{
string text1;
string text2;
WebRequest request1;
string text3;
byte[] buffer1;
byte[] buffer2;
long num1;
byte[] buffer3;
int num2;
WebResponse response1;
byte[] buffer4;
DateTime time1;
long num3;
string[] textArray1;
FileStream stream1 = null;
try
{
fileName = Path.GetFullPath(fileName);
time1 = DateTime.Now;
num3 = time1.Ticks;
text1 = "---------------------" + num3.ToString("x");
if (this.m_headers == null)
{
this.m_headers = new WebHeaderCollection();
}
text2 = this.m_headers["Content-Type"];
if (text2 != null)
{
if (text2.ToLower(CultureInfo.InvariantCulture).StartsWith("multipart/"))
{
throw new WebException(SR.GetString("net_webclient_Multipart"));
}
}
else
{
text2 = "application/octet-stream";
}
this.m_headers["Content-Type"] = "multipart/form-data; boundary=" + text1;
this.m_responseHeaders = null;
stream1 = new FileStream(fileName, FileMode.Open, FileAccess.Read);
request1 = WebRequest.Create(this.GetUri(address));
request1.Credentials = this.Credentials;
this.CopyHeadersTo(request1);
request1.Method = method;
textArray1 = new string[7];
textArray1[0] = "--";
textArray1[1] = text1;
textArray1[2] = "\r\nContent-Disposition: form-data; name=\"file\"; filename=\"";
textArray1[3] = Path.GetFileName(fileName);
textArray1[4] = "\"\r\nContent-Type: ";
textArray1[5] = text2;
textArray1[6] = "\r\n\r\n";
text3 = string.Concat(textArray1);
buffer1 = Encoding.UTF8.GetBytes(text3);
buffer2 = Encoding.ASCII.GetBytes("\r\n--" + text1 + "\r\n");
num1 = 9223372036854775807;
try
{
num1 = stream1.Length;
request1.ContentLength = ((num1 + ((long) buffer1.Length)) + ((long) buffer2.Length));
}
catch
{
}
buffer3 = new byte[Math.Min(((int) 8192), ((int) num1))];
using (Stream stream2 = request1.GetRequestStream())
{
stream2.Write(buffer1, 0, buffer1.Length);
do
{
num2 = stream1.Read(buffer3, 0, buffer3.Length);
if (num2 != 0)
{
stream2.Write(buffer3, 0, num2);
}
}
while ((num2 != 0));
stream2.Write(buffer2, 0, buffer2.Length);
}
stream1.Close();
stream1 = null;
response1 = request1.GetResponse();
this.m_responseHeaders = response1.Headers;
return this.ResponseAsBytes(response1);
}
catch (Exception exception1)
{
if (stream1 != null)
{
stream1.Close();
stream1 = null;
}
if ((exception1 is WebException) || (exception1 is SecurityException))
{
throw;
}
throw new WebException(SR.GetString("net_webclient"), exception1);
}
return buffer4;
}
lfhlyx 2008-05-09
  • 打赏
  • 举报
回复
什么嘛?提交数据?文件上传?
wuxiaoqqqq 2008-05-09
  • 打赏
  • 举报
回复
还是没看懂你要干什么。
huaer1011 2008-05-09
  • 打赏
  • 举报
回复
关注ing
smallfz 2008-05-09
  • 打赏
  • 举报
回复
lz要做个啥玩艺?垃圾发布机器人?
christ2 2008-05-09
  • 打赏
  • 举报
回复
登陆我是知道拉,主要想知道怎么上传文件?
优途科技 2008-05-07
  • 打赏
  • 举报
回复
忘了顶你了!
优途科技 2008-05-07
  • 打赏
  • 举报
回复
搬板凳学习!
leo5381544 2008-05-07
  • 打赏
  • 举报
回复
前两天看过篇关于模拟登录的文章,可惜找不到地址了(还好当时把示例代码下载了)
如果你需要email给我 leo.sun.jie@msn.com
leo5381544 2008-05-07
  • 打赏
  • 举报
回复
[Quote=引用 4 楼 dk385 的回复:]
先用http抓包工具(如HTTPDebuger)看下正常提交页面时Post了那些数据,然后程序再根据这些数据的格式来构建请求,再Post过去。
[/Quote]

接着说, 一般post数据都需要登录, 在post数据前,先需要程序模拟登录.
christ2 2008-05-07
  • 打赏
  • 举报
回复
关键是文件数据怎么搞?走人,明天过来继续看。
家鸣 2008-05-07
  • 打赏
  • 举报
回复
先用http抓包工具(如HTTPDebuger)看下正常提交页面时Post了那些数据,然后程序再根据这些数据的格式来构建请求,再Post过去。
christ2 2008-05-07
  • 打赏
  • 举报
回复
就是比如说我要在淘宝上架一个商品,我想用程序实现该如何?
gen06 2008-05-07
  • 打赏
  • 举报
回复
System.Net.WebClient wc = new System.Net.WebClient();
wc.UploadFile(address, filename);
cctaiyang 2008-05-07
  • 打赏
  • 举报
回复
问题描述的不够详细。

110,533

社区成员

发帖
与我相关
我的任务
社区描述
.NET技术 C#
社区管理员
  • C#
  • Web++
  • by_封爱
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告

让您成为最强悍的C#开发者

试试用AI创作助手写篇文章吧