ASP源码
PHP源码
.NET源码
JSP源码
//通过Post发送的数据
string payload="chkbook=book&keyword=管理";
WebRequest req = We***quest.Create("http://localhost/pceo/Search.aspx");
re***ethod = "POST";
re***ontentType = "application/x-www-form-urlencoded";
StringBuilder UrlEncoded = new StringBuilder();
Char[] reserved = {'?', '=', '&'};
byte[] SomeBytes = null;
if (payload != null)
{
int i=0, j;
while(i<pa***ad.Length)
{
j=***load.IndexOfAny(reserved, i);
if (j==-1)
{
Ur***coded.Append(Ht***tility.UrlEncode(pa***ad.Substring(i, pa***ad.Length-i),Sy***m.Text .Encoding .GetEncoding ("gb2312")));
break;
}
Ur***coded.Append(Ht***tility.UrlEncode(pa***ad.Substring(i, j-i),Sy***m.Text .Encoding .GetEncoding ("gb2312")));
Ur***coded.Append(pa***ad.Substring(j,1));
i = j+1;
}
SomeBytes = En***ing.Default.GetBytes(Ur***coded.ToString());
re***ontentLength = So***ytes.Length;
Stream newStream = re***etRequestStream();
ne***ream.Write(SomeBytes, 0, So***ytes.Length);
ne***ream.Close();
}
else
{
re***ontentLength = 0;
}
try
{
WebResponse result = re***etResponse();
Stream ReceiveStream = re***t.GetResponseStream();
Byte[] read = new Byte[512];
int bytes = Re***veStream.Read(read, 0, 512);
tx***ML.InnerHtml = "";
while (bytes > 0)
{
// 注意:
// 下面假定响应使用 UTF-8 作为编码方式。
// 如果内容以 ANSI 代码页形式(例如,932)发送,则使用类似下面的语句:
// Encoding encode = Sy***m.Text.Encoding.GetEncoding("shift-jis");
Encoding encode = Sy***m.Text.Encoding.GetEncoding("gb2312");
tx***ML.InnerHtml = tx***ML.InnerHtml + en***e.GetString(read, 0, bytes);
bytes = Re***veStream.Read(read, 0, 512);
}
}
catch(Exception)
{
tx***ML.InnerHtml = "检索页时出错";
}
出处:狂风之家 BLOG