使用HttpWebRequest提交Form参数老是失败,能帮我看看么?
有这样一个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();