思归等大人帮忙一下,怎么在winform中模拟一个webform的表单提交,其中这个表单是上传文件的 encType=multipart/form-data

luajiu 2005-01-05 11:53:02
如题 ,没有文件上传的可以作到 ,encType=multipart/form-data为中该这么写:

下面是没有文件上传的普通表单提交!

Public Function PostDate(ByVal url As String, ByVal PostData() As String) As String
Dim Post As String = ""
For Each s As String In PostData
Post += s + "&"
Next
Post = Post.Substring(0, Post.Length - 1)
Dim html As String = ""

Dim encoding As Encoding = encoding.GetEncoding("GB2312")
Dim data As Byte() = encoding.GetBytes(Post)
Dim myRequest As HttpWebRequest = CType(WebRequest.Create(url), HttpWebRequest)
myRequest.Method = "POST"
myRequest.ContentType = "application/x-www-form-urlencoded"


myRequest.ContentLength = data.Length
Dim newStream As Stream = myRequest.GetRequestStream()
newStream.Write(data, 0, data.Length)
newStream.Close()
Dim resp As HttpWebResponse = CType(myRequest.GetResponse(), HttpWebResponse)
Dim sr As StreamReader = New StreamReader(resp.GetResponseStream(), System.Text.Encoding.Default)
html = sr.ReadToEnd()

Return html
End Function


使用:
Dim postdata As String() = {"id=luajiu", "pw=xxxx", "ipmask=0"}

Dim strUrl As String = "http://bbs.cau.edu.cn/wusetu.cn/bbslogin"


Dim SessionHtml As String = PostDate(strUrl, postdata)


有文件上传的该怎么改啊!
...全文
360 6 打赏 收藏 转发到动态 举报
写回复
用AI写文章
6 条回复
切换为时间正序
请发表友善的回复…
发表回复
孟子E章 2005-01-06
  • 打赏
  • 举报
回复
也可以用XMLHTTP

http://dotnet.aspx.cc/ShowDetail.aspx?id=4AE836F8-CCB4-4BEF-90B1-25BB1A5E6433
孟子E章 2005-01-06
  • 打赏
  • 举报
回复
http://dotnet.aspx.cc/ShowDetail.aspx?id=D8F961C3-CBC1-4591-143D-236B572EB89F
luajiu 2005-01-06
  • 打赏
  • 举报
回复
晕 ,没有人知道啊!帮帮急用啊!
webserv2 2005-01-06
  • 打赏
  • 举报
回复
Dim myWebClient As New WebClient
Dim responseArray As Byte() = myWebClient.UploadFile(uriString, "POST", fileName)
dim html as string=Encoding.Default.GetString(responseArray)
saucer 2005-01-06
  • 打赏
  • 举报
回复
1.you could use WebClient.UploadFile method, but needs cooperation on the server side, see

http://msdn.microsoft.com/library/default.asp?url=/library/en-us/cpref/html/frlrfsystemnetwebclientclassuploadfiletopic.asp

2. you need to send the data in the specific format, see the format here

http://aspzone.com/articles/160.aspx
luajiu 2005-01-06
  • 打赏
  • 举报
回复
孟子大哥:那个那种上传不是我想要的,我现在只有一个表单 只知道一个action=/cgi-bin/upload/BXEHNAFOLCJVZMQQFAEBBCJBGHIQTVEXP 如下:

<FORM name=frmUpload action=/cgi-bin/upload/BXEHNAFOLCJVZMQQFAEBBCJBGHIQTVEXP method=post encType=multipart/form-data>上载附件: <INPUT type=file name=file><INPUT onclick="this.value='附件上载中,请稍候...';this.disabled=true;frmUpload.submit();" type=submit value=上载></FORM>

我并不知道他要不文件保持在哪里,我只要模拟这一提交过程就好了,

16,556

社区成员

发帖
与我相关
我的任务
社区描述
VB技术相关讨论,主要为经典vb,即VB6.0
社区管理员
  • VB.NET
  • 水哥阿乐
  • 无·法
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

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