111,023
社区成员
发帖
与我相关
我的任务
分享
//向网页提交数据并接收返回信息:
private string httpPost(string URI, string Parameters)
{
ASCIIEncoding encoding=new ASCIIEncoding();
byte[] bytes = encoding.GetBytes(Parameters);
HttpWebRequest req = (HttpWebRequest)WebRequest.Create(URI);
req.ContentLength = bytes.Length;
req.ContentType = "application/x-www-form-urlencoded";
req.Method = "POST";
string sReturn = "";
try
{
req.ContentLength = bytes.Length;
Stream os = req.GetRequestStream();
os.Write(bytes, 0, bytes.Length);
os.Close();
HttpWebResponse resp = (HttpWebResponse)req.GetResponse();
if (resp == null) return null;
StreamReader sr = new StreamReader(resp.GetResponseStream(), Encoding.GetEncoding("gb2312"));
sReturn = sr.ReadToEnd().Trim();
resp.Close(); sr.Close();
}
catch(Exception e)
{
MessageBox.Show(e.Message);
}
return sReturn;
}
string temp = httpPost( "http://haoma.qq.com/login.php", "u=&p=1C9358BB74DF0D9D4AA6933819017E32&verifycode=&h=1&aid=8000202&u1=http%3A%2F%2Fhaoma.qq.com%2Finfo.php&Submit=Submit");