社区
C#
帖子详情
关于HttpWebRequest的问题
bupo_007
2008-03-20 11:22:00
我想写一个登陆学校图书馆的程序获,取借阅信息
登陆图书馆需要用户名和密码
string url2 = "http://59.64.144.2/reader/infoList.jsp";//登陆页面的连接
怎么用密码和用户名参数登陆呢
myHttpWebRequest.ContentType = "application/x-www-form-urlencoded";
这句中是什么意思
...全文
99
4
打赏
收藏
关于HttpWebRequest的问题
我想写一个登陆学校图书馆的程序获,取借阅信息 登陆图书馆需要用户名和密码 string url2 = "http://59.64.144.2/reader/infoList.jsp";//登陆页面的连接 怎么用密码和用户名参数登陆呢 myHttpWebRequest.ContentType = "application/x-www-form-urlencoded"; 这句中是什么意思
复制链接
扫一扫
分享
转发到动态
举报
写回复
配置赞助广告
用AI写文章
4 条
回复
切换为时间正序
请发表友善的回复…
发表回复
打赏红包
bupo_007
2008-03-21
打赏
举报
回复
每人帮帮忙吗
谢了大牛们!
bupo_007
2008-03-20
打赏
举报
回复
还有我还想调用网页上的图书检索功能,不知能否实现
怎么实现呢
bupo_007
2008-03-20
打赏
举报
回复
string url = "http://59.64.144.2/reader/login.jsp?str_kind=login";
string url2 = "http://59.64.144.2/reader/infoList.jsp";
string indata = "barcode=" + user + "&password=" + psw;
string outdata = "";//return string
CookieContainer myCookieContainer = new CookieContainer();
//新建一个CookieContainer来存放Cookie集合
HttpWebRequest myHttpWebRequest = (HttpWebRequest)WebRequest.Create(url);
//新建一个HttpWebRequest
myHttpWebRequest.ContentType = "application/x-www-form-urlencoded";
myHttpWebRequest.ContentLength = indata.Length;
myHttpWebRequest.Method = "POST";
myHttpWebRequest.CookieContainer = myCookieContainer;
//设置HttpWebRequest的CookieContainer为刚才建立的那个myCookieContainer
Stream myRequestStream = myHttpWebRequest.GetRequestStream();
StreamWriter myStreamWriter = new StreamWriter(myRequestStream, Encoding.GetEncoding("gb2312"));
myStreamWriter.Write(indata);
//把数据写入HttpWebRequest的Request流
myStreamWriter.Close();
myRequestStream.Close();
//关闭打开对象
HttpWebResponse myHttpWebResponse = (HttpWebResponse)myHttpWebRequest.GetResponse();
//新建一个HttpWebResponse
myHttpWebResponse.Cookies = myCookieContainer.GetCookies(myHttpWebRequest.RequestUri);
//获取一个包含url的Cookie集合的CookieCollection
Stream myResponseStream = myHttpWebResponse.GetResponseStream();
//StreamReader myStreamReader = new StreamReader(myResponseStream, Encoding.GetEncoding("gb2312"));
StreamReader myStreamReader = new StreamReader(myResponseStream, Encoding.Default);
outdata = myStreamReader.ReadToEnd();
//把数据从HttpWebResponse的Response流中读出
myStreamReader.Close();
myResponseStream.Close();
//显示"登录"
//拿到了Cookie,再进行请求就能直接读取到登录后的内容了
myHttpWebRequest = (HttpWebRequest)WebRequest.Create(url2);
myHttpWebRequest.CookieContainer = myCookieContainer;//*
//刚才那个CookieContainer已经存有了Cookie,把它附加到HttpWebRequest中则能直接通过验证
myHttpWebResponse = (HttpWebResponse)myHttpWebRequest.GetResponse();
myHttpWebResponse.Cookies = myCookieContainer.GetCookies(myHttpWebRequest.RequestUri);
myResponseStream = myHttpWebResponse.GetResponseStream();
//myStreamReader = new StreamReader(myResponseStream, Encoding.GetEncoding("gb2312"));
myStreamReader = new StreamReader(myResponseStream, Encoding.Default);
outdata = myStreamReader.ReadToEnd();
myStreamReader.Close();
myResponseStream.Close();
//Console.WriteLine(outdata);
return outdata;
}
这是别人写的代码,其中
string indata = "barcode=" + user + "&password=" + psw;
barcode和&passwords是怎么来的呢?
珍惜生命远离CPP
2008-03-20
打赏
举报
回复
myHttpWebRequest.ContentType = "application/x-www-form-urlencoded";
URL编码,也就是你提交的数据内容编码
你需要使用POST的方式提交你的用户名密码。
HttpWebRequest
详解
HttpWebRequest
详解
HttpWebRequest
详解
HttpWebRequest
详解
火车头7.6版采集https插件:网站报错System.Net.
HttpWebRequest
问题
解决方案
解决火车头7.6网站报错System.Net.
HttpWebRequest
问题
的处理 插件 无限制。 https.dll 永久使用无限制版本https
c#
httpwebrequest
调用webservice demo
httpwebrequest
调用webservice返回数据
wphone WebClient和
HttpWebRequest
window phone WebClient和
HttpWebRequest
并解决gb2312乱码
问题
httpwebrequest
httpwebrequest
封装类
C#
110,538
社区成员
642,577
社区内容
发帖
与我相关
我的任务
C#
.NET技术 C#
复制链接
扫一扫
分享
社区描述
.NET技术 C#
社区管理员
加入社区
获取链接或二维码
近7日
近30日
至今
加载中
查看更多榜单
社区公告
让您成为最强悍的C#开发者
试试用AI创作助手写篇文章吧
+ 用AI写文章