using MSXML2;
string url = "http://www.s**.com";
XMLHTTPClass myXMLHTTP = new XMLHTTPClass();
//string url = "http://www.s**.com";
myXMLHTTP.open("GET", url, false, "", "");
myXMLHTTP.send("");
this.textBox1.Text = myXMLHTTP.responseText;
+++++++++++++++++++++++++++++++++++++++
public static CookieContainer PostLogin()
{
string url = "http://www.s**.com";
//string args = "username=c5k00144&passwd=aa0000";
//string outdata = "";
string args = "";
string outdata = "";
Encoding encoding = Encoding.GetEncoding("gb2312");
CookieCollection myCookies = null;
CookieContainer myCookieContainer = new CookieContainer();
HttpWebRequest myHttpWebRequest = (HttpWebRequest)WebRequest.Create(url);
myHttpWebRequest.Accept = "image/gif, image/x-xbitmap, image/jpeg, image/pjpeg, application/vnd.ms-excel, application/msword, application/x-shockwave-flash, */*";
//myHttpWebRequest.Referer = "http://www.s**.com";
myHttpWebRequest.UserAgent = "Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1; SV1; Maxthon; .NET CLR 2.0.50727)";
myHttpWebRequest.ContentType = "application/x-www-form-urlencoded";
myHttpWebRequest.Method = "POST";
myHttpWebRequest.CookieContainer = myCookieContainer;
// 写入
byte[] b = encoding.GetBytes(args);
myHttpWebRequest.ContentLength = b.Length;
using (System.IO.Stream sw = myHttpWebRequest.GetRequestStream())
{
sw.Write(b, 0, b.Length);
if (sw != null)
sw.Close();
}
HttpWebResponse response = null;
System.IO.StreamReader sr = null;
response = (HttpWebResponse)myHttpWebRequest.GetResponse();
myCookies = response.Cookies;
sr = new System.IO.StreamReader(response.GetResponseStream(), encoding);
outdata = sr.ReadToEnd();
return myCookieContainer;
}
public static string GETCommand(string url, CookieContainer myCookieContainer)
{
string outdata = "";
Encoding encoding = Encoding.GetEncoding("gb2312");
HttpWebRequest myHttpWebRequest = (HttpWebRequest)WebRequest.Create(url);
myHttpWebRequest.ContentType = "text/html";
myHttpWebRequest.Method = "GET";
myHttpWebRequest.CookieContainer = myCookieContainer;
HttpWebResponse response = null;
System.IO.StreamReader sr = null;
response = (HttpWebResponse)myHttpWebRequest.GetResponse();
sr = new System.IO.StreamReader(response.GetResponseStream(), encoding);
outdata = sr.ReadToEnd();
return outdata;
}
private string GetContentFromUrll(string _requestUrl)
{
string _StrResponse = "";
HttpWebRequest _WebRequest = (HttpWebRequest)WebRequest.Create(_requestUrl);
_WebRequest.Method = "GET";
WebResponse _WebResponse = _WebRequest.GetResponse();
System.IO.StreamReader _ResponseStream = new System.IO.StreamReader(_WebResponse.GetResponseStream(), System.Text.Encoding.GetEncoding("gb2312"));
_StrResponse = _ResponseStream.ReadToEnd();
_WebResponse.Close();
_ResponseStream.Close();
return _StrResponse;
}
public string GetContentFromWeb(string url, string acyuser, string acypass, string indata)
{
StringBuilder sb = new StringBuilder();
object acyen = false;
XMLHTTPClass myXMLHTTP = new XMLHTTPClass();
try
{
myXMLHTTP.open("get", url, acyen, acyuser, acypass);
myXMLHTTP.setRequestHeader("Accept-Lauguage", "zh-cn");
myXMLHTTP.setRequestHeader("Content-Type", "text/html;charset=gb2312");
myXMLHTTP.send(indata);
//byte[] DefaultBytes = (byte[])myXMLHTTP.responseBody;
//sb.Append(Encoding.Default.GetString(DefaultBytes));
sb.Append(myXMLHTTP.responseText);
}
catch (Exception ex)
{
string tmp = ex.Message;
return "";
}
return sb.ToString();
}
public string GetContentFromWeb(string url, string indata)
{
StringBuilder sb = new StringBuilder();
object acyen = false;
object acyuser = null;
object acypass = null;
XMLHTTPClass myXMLHTTP = new XMLHTTPClass();
try
{
myXMLHTTP.open("get", url, acyen, acyuser, acypass);
myXMLHTTP.setRequestHeader("Accept-Lauguage", "zh-cn");
myXMLHTTP.setRequestHeader("Content-Type", "text/html;charset=gb2312");
myXMLHTTP.send(indata);
sb.Append(myXMLHTTP.responseText);
}
catch (Exception ex)
{
string tmp = ex.Message;
return "";
}
return sb.ToString();
}
public string GetContent(string url)
{
string content = "";
HttpWebRequest myHttpWebRequest = (HttpWebRequest)WebRequest.Create(url);
HttpWebResponse myHttpWebResponse = (HttpWebResponse)myHttpWebRequest.GetResponse();
// WebResponse myResponseStream = myHttpWebResponse.GetResponseStream();
System.IO.Stream myResponseStream = myHttpWebResponse.GetResponseStream();
System.IO.StreamReader myStreamReader = new System.IO.StreamReader(myResponseStream, Encoding.GetEncoding("gb2312"));
content = myStreamReader.ReadToEnd();
myStreamReader.Close();
myResponseStream.Close();
return content;
}
【推荐】国内首个AI IDE,深度理解中文开发场景,立即下载体验Trae
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步
· AI与.NET技术实操系列:基于图像分类模型对图像进行分类
· go语言实现终端里的倒计时
· 如何编写易于单元测试的代码
· 10年+ .NET Coder 心语,封装的思维:从隐藏、稳定开始理解其本质意义
· .NET Core 中如何实现缓存的预热?
· 25岁的心里话
· 闲置电脑爆改个人服务器(超详细) #公网映射 #Vmware虚拟网络编辑器
· 零经验选手,Compose 一天开发一款小游戏!
· 因为Apifox不支持离线,我果断选择了Apipost!
· 通过 API 将Deepseek响应流式内容输出到前端
2006-05-17 初学ASP.Net时一些备忘的东西
2006-05-17 如何给Asp.Net表格或控件加上自定义的提示框?
2006-05-17 如何显示在线人数,和所在位置?? [转自作者:子扬]