I am going to write an application as following : There is a web application which via this web application,agencies communicate with central organization(sending data) Now ,One of these agencies needs an application as below : prepare a copy of data when a user enters data to web application form. I decide to write a windows application and using webbrowser control,that getting data from web pages. the problem is some tags and controls have no id or name which identify and getting data of them.is there any idea for solving. Thanks in advance
Asked
Active
Viewed 1,395 times
1 Answers
0
If you know what kind of data the target web application expects, I suppose you could, instead of using a web browser control, replicate the form in a C# application and post the data using HttpWebRequest or similar.
HttpWebRequest httpRequest = (HttpWebRequest)WebRequest.Create("http://the.url/");
httpRequest.Method = "POST";
httpRequest.ContentType = "application/x-www-form-urlencoded";
string poststring = String.Format("field1={0}&field2={1}",text1.Text,text2.Text);
byte[] bytedata = Encoding.UTF8.GetBytes(poststring);
httpRequest.ContentLength = bytedata.Length;
Stream requestStream = httpRequest.GetRequestStream();
requestStream.Write(bytedata, 0, bytedata.Length);
requestStream.Close();
HttpWebResponse httpWebResponse = (HttpWebResponse)httpRequest.GetResponse();
// Handle the response
Where field1
and field2
etc. represents the POST variables that the web application expects.
If you need to log in first you need to handle this as well, first send a login request and store the session id using a CookieContainer, as shown here:
C# keep session id over httpwebrequest
Once you have got this working you could actually load the response into a web browser as described here.
Load web browser with web response
If you need the web browser control to retain the login cookie perhaps this may be of help
-
what does replicate the form in a C# application mean? – samira Apr 24 '13 at 09:12
-
I mean, create a WinForms or WPF application with the same fields (text boxes etc) as the web application. – havardhu Apr 24 '13 at 09:15