Asked by:
interface to another website

Question
-
User-1664485818 posted
Hi folks, is possible to input directly from my website to https://www.check-mot.service.gov.uk/
i.e. customer inputs their vehicle registration and make into a web form on my website, I then send this data to https://www.check-mot.service.gov.uk/
capture the output and display the results back onto my website?
Monday, May 2, 2016 10:57 PM
All replies
-
User36583972 posted
Hi brucey,
As far as I know, we will try the following two cases.
1: Use Web API
If you use Web API to implement this need. Your only difficulty is to ask this site provides an interface, then you can send data to this website and display the results back to your website.
Learn About ASP.NET Web API:
http://www.asp.net/web-api/overview/getting-started-with-aspnet-web-api
2: Simulation Website Login
This implementation is more cumbersome, because it has a lot of uncertainty.
You can refer the following post.
Using c#/ASP.NET to programmatically fake a login to a website:
Best Regards,
Yohann Lu
Tuesday, May 3, 2016 1:31 AM -
User-1664485818 posted
Thanks Yohann Lu, unfortunately they will not be releasing an interface anytime soon,
Tuesday, May 3, 2016 2:32 PM -
User2053451246 posted
It's definitely not a recommended way to do it, but view the source of that page and look for the <form> tag. As long as you submit to the same action, with the same field names, it should process like it was submitted from that site. This is of course unless they have an anti forgery token on the page, which would make it impossible.
Tuesday, May 3, 2016 3:20 PM -
User-1664485818 posted
I have been looking at Ajax request in JavaScript, seems straightforward, has anyone every use Ajax to fire javascript to another website and then rip the html?
Tuesday, May 3, 2016 7:16 PM -
User36583972 posted
Hi brucey,
You can try the following code.
protected void Button1_Click(object sender, EventArgs e) { string data = "Registration number=136260&Vehicle make=make name"; HttpWebRequest request = (HttpWebRequest)WebRequest.Create("https://www.check-mot.service.gov.uk/");//post url // set post headers request.Method = "POST"; request.KeepAlive = true; request.ContentLength = data.Length; request.ContentType = "application/x-www-form-urlencoded"; // write the data to the request stream using (StreamWriter writer = new StreamWriter(request.GetRequestStream())) { writer.Write(data); } //get data and display the results back onto your website HttpWebResponse response = (HttpWebResponse)request.GetResponse(); string myResponse = ""; using (System.IO.StreamReader sr = new System.IO.StreamReader(response.GetResponseStream())) { myResponse = sr.ReadToEnd(); } }
How to use HttpWebRequest and HttpWebResponse in .NET:
http://www.codeproject.com/Articles/6554/How-to-use-HttpWebRequest-and-HttpWebResponse-in-N
Best Regards,
Yohann Lu
Monday, May 9, 2016 10:01 AM