使用HttpWebRequest提交Form参数老是失败,能帮我看看么?

yk2001 2004-11-17 04:45:01
有这样一个form
<form name=post action=post.asp method=post enctype="multipart/form-data">
<input type=hidden name=mid value=30>
<input type=text size=80 name=subject maxlength=60>
<input type="radio" name="emote" value="1.gif" >
<textarea rows=8 cols=100 name=textinfo>
<input type=submit value="添加">
<input type=text name="author" size=12 value="test" onpropertychange="this.style.color='black';" onclick="this.value=''">
<input type=password name="pwd" size=12 >
<input type=text name="pin" size=12 value="test" onpropertychange="this.style.color='black';" onclick="this.value=''">
<input name=uploadfile value="上传" type=file size=33>
</form>

我按如下方式提交参数
mid=30&subject=达到&emote=\"1.gif\"&textinfo=nnnnnn&author=&pwd=&pin=&uploadfile=

系统总是提示输入的参数不正确,有人能帮忙看下么,下面是C#中的提交部分的代码。


HttpWebRequest req = (HttpWebRequest)WebRequest.Create(url);
req.Method = "POST";
req.AllowAutoRedirect = false;
req.KeepAlive = true;
req.ContentType = "multipart/form-data";

StringBuilder UrlEncoded = new StringBuilder();
Char[] reserved = {'?', '=', '&'};
byte[] SomeBytes = null;

if (paramList != null)
{
int i=0, j;
while(i<paramList.Length)
{
j=paramList.IndexOfAny(reserved, i);
if (j==-1)
{
UrlEncoded.Append(HttpUtility.UrlEncode(paramList.Substring(i, paramList.Length-i)));
break;
}
UrlEncoded.Append(HttpUtility.UrlEncode(paramList.Substring(i, j-i)));
UrlEncoded.Append(paramList.Substring(j,1));
i = j+1;
}
SomeBytes = Encoding.GetEncoding("gb2312").GetBytes(UrlEncoded.ToString());
req.ContentLength = SomeBytes.Length;
Stream newStream = req.GetRequestStream();
newStream.Write(SomeBytes, 0, SomeBytes.Length);
newStream.Close();
}
else
{
req.ContentLength = 0;
}

res = (HttpWebResponse)req.GetResponse();


...全文
308 5 打赏 收藏 转发到动态 举报
写回复
用AI写文章
5 条回复
切换为时间正序
请发表友善的回复…
发表回复
dazhu2 2004-11-20
  • 打赏
  • 举报
回复
up
xiaoslong 2004-11-20
  • 打赏
  • 举报
回复
up
yk2001 2004-11-20
  • 打赏
  • 举报
回复
谢谢帮顶,要拿分的赶紧,星期天晚上结贴
yk2001 2004-11-18
  • 打赏
  • 举报
回复
开新贴了,大家过去看看
http://community.csdn.net/Expert/topic/3564/3564322.xml?temp=.7086145
速马 2004-11-17
  • 打赏
  • 举报
回复
用WebClient.UploadValues

110,567

社区成员

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

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

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