请教高手,cs程序登陆到bs系统中怎么做啊? 我有一个cs的程序现在想登陆到一个bs系统中,请大家帮忙了,贴出一段示例代码或者提供能解决问题的链接都可以。 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 private void btnLogin_Click(object sender, EventArgs e) { HttpWebRequest request = (HttpWebRequest)WebRequest.Create("http://s1.warlord.cn/game/login.jsp"); request.CookieContainer = cookie; request.Method = "POST"; string strData = "username=" + txtName.Text + "&password=" + txtPwd.Text + "&randcode=" + txtVert.Text; // Set the 'Method' property of the 'Webrequest' to 'POST'. ASCIIEncoding encoding = new ASCIIEncoding(); byte[] byte1 = encoding.GetBytes(strData); // Set the content type of the data being posted. request.ContentType = "application/x-www-form-urlencoded"; // Set the content length of the string being posted. request.ContentLength = byte1.Length; Stream newStream = request.GetRequestStream(); newStream.Write(byte1, 0, byte1.Length); // Close the Stream object. newStream.Close(); HttpWebResponse response = (HttpWebResponse)request.GetResponse(); Stream receiveStream = response.GetResponseStream(); StreamReader readStream = new StreamReader(receiveStream, Encoding.Default); this.textBox4.Text = readStream.ReadToEnd(); response.Close(); readStream.Close(); if (textBox4.Text.IndexOf("当前城堡") >= 0) { this.DialogResult = DialogResult.OK; this.Close(); return; } MessageBox.Show("用户名、密码或验证码错误,请重新输入"); this.ShowVertImg(); } private CookieContainer cookie = new CookieContainer(); 用Form内嵌axWebBrowser也可以。先用fiddler2抓取登录网站时的post数据。AxWebBrowser wb = new AxSHDocVw.AxWebBrowser();object oNull = "", oPost = "", oHeader = "Content-Type:application/x-www-form-urlencoded";string strPostData = "抓取的post data";oPost = Encoding.GetEncoding("网站使用的char-set").GetBytes(strPostData);wb.Navigate(strUrl, ref oNull, ref oNull, ref oPost, ref oHeader); 我这个是想在cs程序中显示一张照片,现在问题是这照片怎么再写回来啊?就是我怎么把文件夹中的照片放在流里response回来,cs这边怎么接收并显示阿。 拜托大家了,1楼的方法登陆没有问题,现在再帮帮忙吧。 假设我在虚拟目录pic中有一张照片pic1吧,我用1楼方法登陆了,怎么把他弄回来显示在cs程序中,现在肯定是在cs里面了,大家不要说浏览器了。 String url= "http://www.baidu.com/img/logo.gif"; HttpWebRequest request = HttpWebRequest.Create(url) as HttpWebRequest; HttpWebResponse response = request.GetResponse() as HttpWebResponse; String filename = @"c:\logo.gif"; FileStream fs = new FileStream(filename, FileMode.OpenOrCreate, FileAccess.Write); // 本地保存 byte[] buff = new byte[1024 * 10]; // 10KB int length = 0; Stream img = response.GetResponseStream(); while ((length = img.Read(buff, 0, buff.Length)) > 0) { fs.Write(buff, 0, length); offset += length; } fs.Close(); 在返回的html源码里找到图片链接,指定程序图片指向该链接行不? 你应该用WebService...除非你不能控制那个B/S系统才考虑用HTTP GET/POST模式... 登陆之后在服务器中返回要获取的内容Response.AddHeader("Content-Disposition", "attachment; filename=" + HttpUtility.UrlEncode(pic1.jpg")); Response.ContentType = "image/jpeg";Response.WriteFile(("pic")+"\\"+"pic1.jpg");然后在cs程序中.Stream img = response.GetResponseStream(); winform绘制旋转字体的问题 该死的Ntalker C#广域网视频的压缩和传输 问一个关于类的实例化的时机的问题. 如何把ToolStripMenuItem的副本选入上下文菜单。。。? dev express xtragrid ,如何取得当前 girdview的数据集. 请问在C#中自己定义的名称空间有什么用啊? winform程序,如何限制一个textbox,不让输入输个字符? parameter这个类是从哪个命名空间出来的? label付值 基于xml动态界面设计 关于两个 -> 的问题
private void btnLogin_Click(object sender, EventArgs e)
{
HttpWebRequest request =
(HttpWebRequest)WebRequest.Create("http://s1.warlord.cn/game/login.jsp"); request.CookieContainer = cookie;
request.Method = "POST";
string strData = "username=" + txtName.Text + "&password=" + txtPwd.Text + "&randcode=" + txtVert.Text; // Set the 'Method' property of the 'Webrequest' to 'POST'.
ASCIIEncoding encoding = new ASCIIEncoding();
byte[] byte1 = encoding.GetBytes(strData); // Set the content type of the data being posted.
request.ContentType = "application/x-www-form-urlencoded"; // Set the content length of the string being posted.
request.ContentLength = byte1.Length; Stream newStream = request.GetRequestStream(); newStream.Write(byte1, 0, byte1.Length); // Close the Stream object.
newStream.Close();
HttpWebResponse response = (HttpWebResponse)request.GetResponse();
Stream receiveStream = response.GetResponseStream();
StreamReader readStream = new StreamReader(receiveStream, Encoding.Default); this.textBox4.Text = readStream.ReadToEnd();
response.Close();
readStream.Close();
if (textBox4.Text.IndexOf("当前城堡") >= 0)
{
this.DialogResult = DialogResult.OK;
this.Close();
return;
}
MessageBox.Show("用户名、密码或验证码错误,请重新输入");
this.ShowVertImg();
}
AxWebBrowser wb = new AxSHDocVw.AxWebBrowser();
object oNull = "", oPost = "", oHeader = "Content-Type:application/x-www-form-urlencoded";
string strPostData = "抓取的post data";
oPost = Encoding.GetEncoding("网站使用的char-set").GetBytes(strPostData);
wb.Navigate(strUrl, ref oNull, ref oNull, ref oPost, ref oHeader);
拜托大家了,1楼的方法登陆没有问题,现在再帮帮忙吧
。
现在肯定是在cs里面了,大家不要说浏览器了。
String url= "http://www.baidu.com/img/logo.gif";
HttpWebRequest request = HttpWebRequest.Create(url) as HttpWebRequest;
HttpWebResponse response = request.GetResponse() as HttpWebResponse;
String filename = @"c:\logo.gif";
FileStream fs = new FileStream(filename, FileMode.OpenOrCreate, FileAccess.Write); // 本地保存 byte[] buff = new byte[1024 * 10]; // 10KB
int length = 0;
Stream img = response.GetResponseStream(); while ((length = img.Read(buff, 0, buff.Length)) > 0)
{
fs.Write(buff, 0, length);
offset += length;
}
fs.Close();
登陆之后在服务器中返回要获取的内容
Response.AddHeader("Content-Disposition", "attachment; filename=" + HttpUtility.UrlEncode(pic1.jpg"));
Response.ContentType = "image/jpeg";
Response.WriteFile(("pic")+"\\"+"pic1.jpg");然后在cs程序中.
Stream img = response.GetResponseStream();