包括与WebRequest的登录凭据 [英] including login credentials with a WebRequest
问题描述
我想幕后自己登录到一个网站,从后面我的ASP.NET网站VB code。但我傻眼了对如何做到这一点。
I am trying to "behind the scenes" log myself into a website, from the VB code behind my ASP.NET website. But I am dumbfounded as to how to do this.
据我知道我应该使用的WebRequest
或 Web客户端
类。这是大约相当于我知道了。我不知道如何使用类。
As far as I know I should be using the WebRequest
or Webclient
class. That is about as much as I know. I am not sure how to use the class.
我要点击我的网站上的一个按钮,并有其点击
事件发送用户名和密码到另一个网站。这个网站的其他附属ISOT与我。我知道这个概念看似愚蠢,但我打算以后再考虑这一点,只是现在需要知道这一点。
I want to click a button on my website and have its Click
event send a username and password to another website. This other site isot affiliated with mine. I realize the concept may seem stupid, but I plan on taking this further later, but Just need to know this now.
如果任何人都可以给我一些code例如使用说明或直接我一个很好的教程,这将是极大的AP preciated!
If anyone could give me some code example with explanation or direct me to a good tutorial that would be greatly appreciated!
如果它有助于在所有,我试图登录到该网站是www.Lockerz.com
If it helps at all, the website I am trying to log into is www.Lockerz.com
谢谢!
推荐答案
如果客户端站点使用基本身份验证,您可以添加这样的凭据:
If the client site uses basic authentication you can add credentials like this:
WebRequest myReq = WebRequest.Create(url);
CredentialCache mycache = new CredentialCache();
mycache.Add(new Uri(url), "Basic", new NetworkCredential(username, password));
myReq.Credentials = mycache;
如果它使用的形式登录,您可以使用Fiddler嗅出贴在登录数据,并执行从HttpWebRequest对象相同的请求。你可能想处理cookie,以及如果必须执行与登录用户的多个请求。
If it uses form login, you can use Fiddler to sniff the data posted on a login, and perform the same request from a HttpWebRequest object. You might want to handle cookies as well if you have to perform multiple requests with the logged in user.
参考:
- 饼干:<一href=\"http://stackoverflow.com/questions/571964/automatic-cookie-handling-c-net-httpwebrequesthttpwebresponse\">http://stackoverflow.com/questions/571964/automatic-cookie-handling-c-net-httpwebrequesthttpwebresponse
- 饼干和POST:<一href=\"http://stackoverflow.com/questions/1581755/httpwebrequest-post-and-cookies\">http://stackoverflow.com/questions/1581755/httpwebrequest-post-and-cookies
- 下载类:<一href=\"http://stackoverflow.com/questions/2700638/2700707#2700707\">http://stackoverflow.com/questions/2700638/2700707#2700707
这篇关于包括与WebRequest的登录凭据的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!