I am new to the visualstudio.net
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:
---------------------------------------------------------------------------------------------------------------------------------------------------
'WindowsFormsApplication1.vshost.exe' (Managed): Loaded 'C:\Windows\assembly\GAC_32\mscorlib\2.0.0.0__b77a 5c561934e089\mscorlib.dll'-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
'WindowsFormsApplication1.vshost.exe' (Managed): Loaded 'C:\Windows\assembly\GAC_MSIL\Microsoft.VisualStud io.HostingProcess.Utilities\9.0.0.0__b03f5f7f11d50 a3a\Microsoft.VisualStudio.HostingProcess.Utilitie s.dll'
'WindowsFormsApplication1.vshost.exe' (Managed): Loaded 'C:\Windows\assembly\GAC_MSIL\System.Windows.Forms \2.0.0.0__b77a5c561934e089\System.Windows.Forms.dl l'
'WindowsFormsApplication1.vshost.exe' (Managed): Loaded 'C:\Windows\assembly\GAC_MSIL\System\2.0.0.0__b77a 5c561934e089\System.dll'
'WindowsFormsApplication1.vshost.exe' (Managed): Loaded 'C:\Windows\assembly\GAC_MSIL\System.Drawing\2.0.0 .0__b03f5f7f11d50a3a\System.Drawing.dll'
'WindowsFormsApplication1.vshost.exe' (Managed): Loaded 'C:\Windows\assembly\GAC_MSIL\Microsoft.VisualStud io.HostingProcess.Utilities.Sync\9.0.0.0__b03f5f7f 11d50a3a\Microsoft.VisualStudio.HostingProcess.Uti lities.Sync.dll'
'WindowsFormsApplication1.vshost.exe' (Managed): Loaded 'C:\Windows\assembly\GAC_MSIL\Microsoft.VisualStud io.Debugger.Runtime\9.0.0.0__b03f5f7f11d50a3a\Micr osoft.VisualStudio.Debugger.Runtime.dll'
'WindowsFormsApplication1.vshost.exe' (Managed): Loaded 'C:\Users\Siddharth\Documents\Visual Studio 2008\Projects\WindowsFormsApplication1\WindowsForm sApplication1\bin\Debug\WindowsFormsApplication1.v shost.exe'
'WindowsFormsApplication1.vshost.exe' (Managed): Loaded 'C:\Windows\assembly\GAC_MSIL\System.Core\3.5.0.0_ _b77a5c561934e089\System.Core.dll'
'WindowsFormsApplication1.vshost.exe' (Managed): Loaded 'C:\Windows\assembly\GAC_MSIL\System.Xml.Linq\3.5. 0.0__b77a5c561934e089\System.Xml.Linq.dll'
'WindowsFormsApplication1.vshost.exe' (Managed): Loaded 'C:\Windows\assembly\GAC_MSIL\System.Data.DataSetE xtensions\3.5.0.0__b77a5c561934e089\System.Data.Da taSetExtensions.dll'
'WindowsFormsApplication1.vshost.exe' (Managed): Loaded 'C:\Windows\assembly\GAC_32\System.Data\2.0.0.0__b 77a5c561934e089\System.Data.dll'
'WindowsFormsApplication1.vshost.exe' (Managed): Loaded 'C:\Windows\assembly\GAC_MSIL\System.Deployment\2. 0.0.0__b03f5f7f11d50a3a\System.Deployment.dll'
'WindowsFormsApplication1.vshost.exe' (Managed): Loaded 'C:\Windows\assembly\GAC_MSIL\System.Xml\2.0.0.0__ b77a5c561934e089\System.Xml.dll'
The thread 0x11f0 has exited with code 0 (0x0).
The thread 0x129c has exited with code 0 (0x0).
'WindowsFormsApplication1.vshost.exe' (Managed): Loaded 'C:\Users\Siddharth\Documents\Visual Studio 2008\Projects\WindowsFormsApplication1\WindowsForm sApplication1\bin\Debug\WindowsFormsApplication1.e xe', Symbols loaded.
'WindowsFormsApplication1.vshost.exe' (Managed): Loaded 'C:\Windows\assembly\GAC_MSIL\System.Configuration \2.0.0.0__b03f5f7f11d50a3a\System.Configuration.dl l'
A first chance exception of type 'System.Net.ProtocolViolationException' occurred in System.dll
A first chance exception of type 'System.Net.ProtocolViolationException' occurred in WindowsFormsApplication1.exe
An unhandled exception of type 'System.Net.ProtocolViolationException' occurred in WindowsFormsApplication1.exe
Additional information: Cannot send a content-body with this verb-type.
The program '[3816] WindowsFormsApplication1.vshost.exe: Managed' has exited with code -805306369 (0xcfffffff).
Thanks
Reply awaited
Sid