简体   繁体   English

如何使用自己的asp.net页面访问网站?

[英]How to acess a website using own asp.net page?

I here want to call another website url, login into it, and use one of its function using my asp.net project. 我在这里想调用另一个网站url,登录它,并使用我的asp.net项目使用其功能之一。 I'm working on a project in asp.net where my web based program will send sms to mobile phones. 我正在asp.net中的一个项目中,我的基于Web的程序将向手机发送短信。 Since I don't want to subscribe to any gateways or similar, I found this website: 由于我不想订阅任何网关或类似网关,因此我找到了此网站:

http://sms80.com

Now what I want to do is, from my asp.net page I need to access this website, login and use its service but all this must be done hidden programatically in my asp.net page. 现在我想做的是,我需要从asp.net页面访问该网站,登录并使用其服务,但是所有这些都必须以编程方式隐藏在asp.net页面中。

I somehow inspected that websites element such as login name textbox and password textbox. 我以某种方式检查了该网站元素,例如登录名文本框和密码文本框。 I am not trying to hacking but I just need know the process I do in that website( I login using my account, then write my message and write the mobile num and send) programaticallyin my asp.net. 我不是在尝试黑客攻击,但我只需要在asp.net中以编程方式知道我在该网站上执行的过程(我使用我的帐户登录,然后编写我的消息并编写手机号码并发送)。

I did some research and found out that I can send or pass values in url straight such as: 我进行了一些研究,发现可以直接在url中发送或传递值,例如:

your_url.aspx?your_url_variable=" + @variable_from_form

but it doesn't seem work. 但这似乎没有用。 Is it any other way to do it? 还有其他方法吗?

If the other website doesn't have an API loging into it programmatically is not a simple process. 如果另一个网站没有API,则以编程方式登录到该网站不是一个简单的过程。

It requires a lot of exploratory work and analysis of how the website you're trying to login works. 它需要进行大量探索性工作,并需要分析您要登录的网站的工作方式。 The process consists of first determining what is being sent in the request/response communication post data with a tool such as Fiddler . 该过程包括首先使用诸如Fiddler之类的工具确定请求/响应通信后数据中正在发送的内容。

Then, you need to construct a series of GETs and POSTs using either HttpWebRequest / HttpWebResponse classes or WebClient class so you can mimic the way the browser does it. 然后,您需要使用HttpWebRequest / HttpWebResponse类或WebClient类构造一系列GET和POST,以便模仿浏览器的工作方式。

An example would be: 一个例子是:

string url = "http://sms80.com";
HttpWebRequest http = (HttpWebRequest)WebRequest.Create(url);
http.CookieContainer = _cookieJar;
http.Connection = "Keep-alive";
http.Method = "POST";
http.ContentType = "application/x-www-form-urlencoded";
string postData="username=" + username + "&password=" + password;
byte[] dataBytes = UTF8Encoding.UTF8.GetBytes(postData);
http.ContentLength = dataBytes.Length;
Stream postStream = http.GetRequestStream();
postStream.Write(dataBytes, 0, dataBytes.Length);
postStream.Close();
// see if we're logged in
HttpWebResponse httpResponse = (HttpWebResponse)http.GetResponse();
// continue (read the response etc.)

What you are describing in your question is called "sending form parameters using GET" . 您在问题中描述的内容称为“使用GET发送表单参数” Even though you can potentially intervene here and mimic the data request from HTML form, the server might check for some other data in HTTP header, for example the referring webpage (that should be the page of the form!) and deny executing your request. 即使您可以在此处进行干预并模仿来自HTML表单的数据请求,服务器也可能会在HTTP标头中检查其他数据,例如引用网页(应该是表单的页面!),并拒绝执行您的请求。 I can imagine that a site designed for sending SMS might have this protection mechanism. 我可以想象一个设计用于发送SMS的站点可能具有这种保护机制。

The correct way to implement the feature is to request access to API, eg to the web-services you might call from your application to perform certain action, like sending SMS. 实现此功能的正确方法是请求访问API,例如,您可能会从应用程序调用以执行某些操作(例如发送SMS)的Web服务。 This might be not as cheap as sending SMS from the webform, but this is the only legal method to embed this functionality in your application! 这可能不如从网络表单发送SMS便宜,但这是将此功能嵌入到您的应用程序中的唯一合法方法!

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM