// Data sent through post
String payload = "chkbook = book & keyword = manage ";
Webrequest Req = webrequest. Create ("http: // localhost/pceo/search. aspx ");
Req. method = "Post ";
Req. contenttype = "application/X-WWW-form-urlencoded ";
Stringbuilder urlencoded = new stringbuilder ();
Char [] reserved = {'? ',' = ','&'};
Byte [] somebytes = NULL;
If (payload! = NULL)
{
Int I = 0, J;
While (I <payload. length)
{
J = payload. indexofany (reserved, I );
If (j =-1)
{
Urlencoded. append (httputility. urlencode (payload. substring (I, payload. Length-I), system. Text. encoding. getencoding ("gb2312 ″)));
Break;
}
Urlencoded. append (httputility. urlencode (payload. substring (I, j-I), system. Text. encoding. getencoding ("gb2312 ″)));
Urlencoded. append (payload. substring (J, 1 ));
I = J + 1;
}
Somebytes = encoding. Default. getbytes (urlencoded. tostring ());
Req. contentlength = somebytes. length;
Stream newstream = Req. getrequeststream ();
Newstream. Write (somebytes, 0, somebytes. Length );
Newstream. Close ();
}
Else
{
Req. contentlength = 0;
}
Try
{
Webresponse result = Req. getresponse ();
Stream receivestream = result. getresponsestream ();
Byte [] READ = new byte [512];
Int bytes = receivestream. Read (read, 0,512 );
Txthtml. innerhtml = "";
While (Bytes> 0)
{
// Note:
// The following assumes that the response uses the UTF-8 as the encoding method.
// If the content is ANSI Code The following statement is used to send messages in the form of pages (for example, 932:
// Encoding encode = system. Text. encoding. getencoding ("shift-JIS ");
Encoding encode = system. Text. encoding. getencoding ("gb2312 ″);
Txthtml. innerhtml = txthtml. innerhtml + encode. getstring (read, 0, bytes );
Bytes = receivestream. Read (read, 0,512 );
}
}
Catch (exception)
{
Txthtml. innerhtml = "An error occurred while retrieving the page ";
}