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

2019-08-22 09:13发布

I here want to call another website url, login into it, and use one of its function using my asp.net project. I'm working on a project in asp.net where my web based program will send sms to mobile phones. 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.

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.

I did some research and found out that I can send or pass values in url straight such as:

your_url.aspx?your_url_variable=" + @variable_from_form

but it doesn't seem work. Is it any other way to do it?

2条回答
Anthone
2楼-- · 2019-08-22 09:33

If the other website doesn't have an API loging into it programmatically is not a simple process.

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.

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.

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.)
查看更多
何必那么认真
3楼-- · 2019-08-22 09:46

What you are describing in your question is called "sending form parameters using 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. I can imagine that a site designed for sending SMS might have this protection mechanism.

The correct way to implement the feature is to request access to API, e.g. to the web-services you might call from your application to perform certain action, like sending SMS. 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!

查看更多
登录 后发表回答