I am new to the visualstudio.ne t
I am trying to develop an application which requires me to send data to a HTML webpage - http://patft.uspto.gov/netahtml/PTO/search-bool.html
and the user sendsd the data to the webpage and receives the response to that particular values from the webpage.
I am trying to use httpwebrequest for this purpose, but I am receiving errors, kindly let me know where I am going wrong. When I llok at the source code of the form I realize that it has a GET method and I am trying to sned values to that GET method through my application (windowsforms - c sharp) and is npt able to send it.
------------------------------------------------------------------------------------------------
My code is as follows:
------------------------------------------------------------------------------------------------
Expand|Select|Wrap|Line Numbers
- public Form2(TextBox t)
- {
- InitializeComponent();
- label1.Text = t.Text;
- StringBuilder sb = new StringBuilder();
- byte[] buf = new byte[100000000];
- try
- {
- string webpage_data = t.Text + "&FIELD1=ASNM";
- // string webpage_data = "TERM1=" + t.Text + "&FIELD1=ASNM";
- // string webpage = "http://patft.uspto.gov/netacgi/nph-Parser";
- string webpage = "http://patft.uspto.gov/netahtml/PTO/search-bool.html";
- ASCIIEncoding encoding = new ASCIIEncoding();
- byte[] data = encoding.GetBytes(webpage_data);
- // webpage = webpage + "?" + webpage_data;
- HttpWebRequest myRequest = (HttpWebRequest)WebRequest.Create(webpage);
- myRequest.Credentials = CredentialCache.DefaultCredentials;
- myRequest.ContentLength = data.Length;
- myRequest.Method = "GET";
- myRequest.ContentType = "application/x-www-form-urlencoded";
- myRequest.ContentLength = data.Length;
- Stream newStream = myRequest.GetRequestStream();
- newStream.Write(data, 0, data.Length);
- HttpWebResponse response = (HttpWebResponse)myRequest.GetResponse();
- Stream receive_stream = response.GetResponseStream();
- StreamReader read_stream = new StreamReader(receive_stream, Encoding.UTF8);
- string str = read_stream.ReadToEnd();
- newStream.Close();
- // response.GetResponseStream(read_stream.ReadToEnd());
- response.Close();
- read_stream.Close();
- richTextBox1.Text = str;
- }
- catch (Exception)
- {
- throw;
- }
- }
and the log at the output tab is as follows:
---------------------------------------------------------------------------------------------------------------------------------------------------
'WindowsFormsAp plication1.vsho st.exe' (Managed): Loaded 'C:\Windows\ass embly\GAC_32\ms corlib\2.0.0.0_ _b77a5c561934e0 89\mscorlib.dll '-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
'WindowsFormsAp plication1.vsho st.exe' (Managed): Loaded 'C:\Windows\ass embly\GAC_MSIL\ Microsoft.Visua lStudio.Hosting Process.Utiliti es\9.0.0.0__b03 f5f7f11d50a3a\M icrosoft.Visual Studio.HostingP rocess.Utilitie s.dll'
'WindowsFormsAp plication1.vsho st.exe' (Managed): Loaded 'C:\Windows\ass embly\GAC_MSIL\ System.Windows. Forms\2.0.0.0__ b77a5c561934e08 9\System.Window s.Forms.dll'
'WindowsFormsAp plication1.vsho st.exe' (Managed): Loaded 'C:\Windows\ass embly\GAC_MSIL\ System\2.0.0.0_ _b77a5c561934e0 89\System.dll'
'WindowsFormsAp plication1.vsho st.exe' (Managed): Loaded 'C:\Windows\ass embly\GAC_MSIL\ System.Drawing\ 2.0.0.0__b03f5f 7f11d50a3a\Syst em.Drawing.dll'
'WindowsFormsAp plication1.vsho st.exe' (Managed): Loaded 'C:\Windows\ass embly\GAC_MSIL\ Microsoft.Visua lStudio.Hosting Process.Utiliti es.Sync\9.0.0.0 __b03f5f7f11d50 a3a\Microsoft.V isualStudio.Hos tingProcess.Uti lities.Sync.dll '
'WindowsFormsAp plication1.vsho st.exe' (Managed): Loaded 'C:\Windows\ass embly\GAC_MSIL\ Microsoft.Visua lStudio.Debugge r.Runtime\9.0.0 .0__b03f5f7f11d 50a3a\Microsoft .VisualStudio.D ebugger.Runtime .dll'
'WindowsFormsAp plication1.vsho st.exe' (Managed): Loaded 'C:\Users\Siddh arth\Documents\ Visual Studio 2008\Projects\W indowsFormsAppl ication1\Window sFormsApplicati on1\bin\Debug\W indowsFormsAppl ication1.vshost .exe'
'WindowsFormsAp plication1.vsho st.exe' (Managed): Loaded 'C:\Windows\ass embly\GAC_MSIL\ System.Core\3.5 .0.0__b77a5c561 934e089\System. Core.dll'
'WindowsFormsAp plication1.vsho st.exe' (Managed): Loaded 'C:\Windows\ass embly\GAC_MSIL\ System.Xml.Linq \3.5.0.0__b77a5 c561934e089\Sys tem.Xml.Linq.dl l'
'WindowsFormsAp plication1.vsho st.exe' (Managed): Loaded 'C:\Windows\ass embly\GAC_MSIL\ System.Data.Dat aSetExtensions\ 3.5.0.0__b77a5c 561934e089\Syst em.Data.DataSet Extensions.dll'
'WindowsFormsAp plication1.vsho st.exe' (Managed): Loaded 'C:\Windows\ass embly\GAC_32\Sy stem.Data\2.0.0 .0__b77a5c56193 4e089\System.Da ta.dll'
'WindowsFormsAp plication1.vsho st.exe' (Managed): Loaded 'C:\Windows\ass embly\GAC_MSIL\ System.Deployme nt\2.0.0.0__b03 f5f7f11d50a3a\S ystem.Deploymen t.dll'
'WindowsFormsAp plication1.vsho st.exe' (Managed): Loaded 'C:\Windows\ass embly\GAC_MSIL\ System.Xml\2.0. 0.0__b77a5c5619 34e089\System.X ml.dll'
The thread 0x11f0 has exited with code 0 (0x0).
The thread 0x129c has exited with code 0 (0x0).
'WindowsFormsAp plication1.vsho st.exe' (Managed): Loaded 'C:\Users\Siddh arth\Documents\ Visual Studio 2008\Projects\W indowsFormsAppl ication1\Window sFormsApplicati on1\bin\Debug\W indowsFormsAppl ication1.exe', Symbols loaded.
'WindowsFormsAp plication1.vsho st.exe' (Managed): Loaded 'C:\Windows\ass embly\GAC_MSIL\ System.Configur ation\2.0.0.0__ b03f5f7f11d50a3 a\System.Config uration.dll'
A first chance exception of type 'System.Net.Pro tocolViolationE xception' occurred in System.dll
A first chance exception of type 'System.Net.Pro tocolViolationE xception' occurred in WindowsFormsApp lication1.exe
An unhandled exception of type 'System.Net.Pro tocolViolationE xception' occurred in WindowsFormsApp lication1.exe
Additional information: Cannot send a content-body with this verb-type.
The program '[3816] WindowsFormsApp lication1.vshos t.exe: Managed' has exited with code -805306369 (0xcfffffff).
Thanks
Reply awaited
Sid