473,473 Members | 2,124 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

How to send data to GET method in HTML using c#

sid0404
16 New Member
Hi

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
  1. public Form2(TextBox t)
  2.         {
  3.             InitializeComponent();
  4.  
  5.             label1.Text = t.Text;
  6.  
  7.             StringBuilder sb = new StringBuilder();
  8.             byte[] buf = new byte[100000000];
  9.  
  10.  
  11.  
  12.             try
  13.             {
  14.                 string webpage_data = t.Text + "&FIELD1=ASNM";
  15.                 //            string webpage_data = "TERM1=" + t.Text + "&FIELD1=ASNM";
  16. //                string webpage = "http://patft.uspto.gov/netacgi/nph-Parser";
  17.                    string webpage = "http://patft.uspto.gov/netahtml/PTO/search-bool.html";
  18.  
  19.                 ASCIIEncoding encoding = new ASCIIEncoding();
  20.                 byte[] data = encoding.GetBytes(webpage_data);
  21. //                webpage = webpage + "?" + webpage_data;
  22.                 HttpWebRequest myRequest = (HttpWebRequest)WebRequest.Create(webpage);
  23.  
  24.                 myRequest.Credentials = CredentialCache.DefaultCredentials;
  25.  
  26.  
  27.                 myRequest.ContentLength = data.Length;
  28.                 myRequest.Method = "GET";
  29.                 myRequest.ContentType = "application/x-www-form-urlencoded";
  30.                 myRequest.ContentLength = data.Length;  
  31.  
  32.                 Stream newStream = myRequest.GetRequestStream();
  33.  
  34.                 newStream.Write(data, 0, data.Length);
  35.  
  36.                 HttpWebResponse response = (HttpWebResponse)myRequest.GetResponse();
  37.                 Stream receive_stream = response.GetResponseStream();
  38.  
  39.                 StreamReader read_stream = new StreamReader(receive_stream, Encoding.UTF8);
  40.  
  41.                 string str = read_stream.ReadToEnd();
  42.  
  43.                 newStream.Close();
  44.  
  45.  
  46.                 //            response.GetResponseStream(read_stream.ReadToEnd());
  47.  
  48.                 response.Close();
  49.                 read_stream.Close();
  50.  
  51.                 richTextBox1.Text = str;
  52.  
  53.             }
  54.             catch (Exception)
  55.             {
  56.  
  57.                 throw;
  58.             }
  59.         }
  60.  
---------------------------------------------------------------------------------------------------------------------------------------------------

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
Jul 7 '08 #1
5 12772
Plater
7,872 Recognized Expert Expert
Well, as the error message says, if you are using the GET method, there is no content data.
Perhaps you wanted the POST method?
Jul 7 '08 #2
sid0404
16 New Member
Well, as the error message says, if you are using the GET method, there is no content data.
Perhaps you wanted the POST method?
I changed my method to the POST and now I am getting the output as the source code of the http://patft.uspto.gov/netahtml/PTO/search-bool.html while I need the output as the HTML code of the web page which is generate when you click on the submit button of the "http://patft.uspto.gov/netahtml/PTO/search-bool.html" web page and not the form itself as this web page does not have any POST method so the code runs fine and gives the output as the source code of this webpage only, so the problem remains the same I can not get the output of the next page which shows the results when you hit the submit button.

The URL used by that webpage is :

http://patft.uspto.gov/netacgi/nph-Parser

do you think I should use that directly instead f the URL i am using , if I use this then I get the System.Net.WebException at the line

HttpWebResponse response = (HttpWebResponse)myRequest.GetResponse();

I think I need to use the
http://patft.uspto.gov/netacgi/nph-Parser

but why am I getting the error message, am i missing something obvious ?
Jul 7 '08 #3
Plater
7,872 Recognized Expert Expert
Ok well then you should be using POST to go to http://patft.uspto.gov//netacgi/nph-Parser

Since that is where the Search button goes to.
You will also probably need to make sure that you have all the correct hidden fields supplied in the content as well.
Jul 7 '08 #4
sid0404
16 New Member
Ok well then you should be using POST to go to http://patft.uspto.gov//netacgi/nph-Parser

Since that is where the Search button goes to.
You will also probably need to make sure that you have all the correct hidden fields supplied in the content as well.

This is what my code look so far, I have issued all the values to the hidden parameters as well, but i think for some reason it is not able to get the response from the server , as i still get the system.net.webexception, the code is

----------------------------------------------------------------------------
Expand|Select|Wrap|Line Numbers
  1.     using System;
  2.     using System.Collections.Generic;
  3.     using System.ComponentModel;
  4.     using System.Data;
  5.     using System.IO;
  6. using System.Net;
  7.     using System.Drawing;
  8.     using System.Linq;
  9.     using System.Text;
  10.     using System.Windows.Forms;
  11.  
  12.     namespace WindowsFormsApplication1
  13.     {
  14.         public partial class Form2 : Form
  15.         {
  16.             public Form2(TextBox t)
  17.             {
  18.                 InitializeComponent();
  19.  
  20.                 label1.Text = t.Text;
  21.  
  22.                 StringBuilder sb = new StringBuilder();
  23.                 byte[] buf = new byte[100000000];
  24.  
  25.                 string webpage_data = "&TERM1=google&FIELD1=ASNM&co1=AND&TERM2=&FIELD2=&d=PTXT";
  26.                 string webpage = "http://patft.uspto.gov//netacgi/nph-Parser?Sect1=PTO2&Sect2=HITOFF&p=1&u=%2Fnetahtml%2FPTO%2Fsearch-bool.html&r=0&f=S&l=50";
  27.           //             string webpage = "http://patft.uspto.gov/netahtml/PTO/search-bool.html";
  28.  
  29.                     ASCIIEncoding encoding = new ASCIIEncoding();
  30.                     byte[] data = encoding.GetBytes(webpage_data);
  31.                     webpage = webpage + "?"+ webpage_data;
  32.                     HttpWebRequest myRequest = (HttpWebRequest)WebRequest.Create(webpage);
  33.  
  34.                     myRequest.Credentials = CredentialCache.DefaultCredentials;
  35.                     myRequest.Method = "POST";
  36.  
  37.     /*            
  38.                     myRequest.ContentLength = data.Length;
  39.                     myRequest.Method = "POST";
  40.                     myRequest.ContentType = "application/x-www-form-urlencoded";
  41.                     myRequest.ContentLength = data.Length;   
  42.  
  43.                     Stream newStream = myRequest.GetRequestStream();
  44.  
  45.                     newStream.Write(data, 0, data.Length);
  46. */                
  47.                     HttpWebResponse response = (HttpWebResponse)myRequest.GetResponse();
  48.                     Stream receive_stream = response.GetResponseStream();
  49.  
  50.                     StreamReader read_stream = new StreamReader(receive_stream, Encoding.UTF8);
  51.  
  52.                     string str = read_stream.ReadToEnd();
  53.  
  54.         //            newStream.Close();
  55.  
  56.  
  57.                     //            response.GetResponseStream(read_stream.ReadToEnd());
  58.  
  59.                     response.Close();
  60.                     read_stream.Close();
  61.  
  62.                     richTextBox1.Text = str;
  63.  
  64.     //            }
  65.             }
  66.  
  67.             private void label1_Click(object sender, EventArgs e)
  68.             {
  69.  
  70.             }
  71.  
  72.             private void richTextBox1_TextChanged(object sender, EventArgs e)
  73.             {
  74.  
  75.             }
  76.         }
  77.     }
  78.  
----------------------------------------------------------------------------
while the log on the output tab looks like this :
----------------------------------------------------------------------------
'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 0x9d4 has exited with code 0 (0x0).
The thread 0x10b8 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.
A first chance exception of type 'System.IO.FileNotFoundException' occurred in mscorlib.dll
'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.ObjectDisposedException' occurred in System.dll
A first chance exception of type 'System.Net.WebException' occurred in System.dll
An unhandled exception of type 'System.Net.WebException' occurred in System.dll

Additional information: The server committed a protocol violation. Section=ResponseStatusLine

The thread 0x1210 has exited with code 0 (0x0).
The program '[4712] WindowsFormsApplication1.vshost.exe: Managed' has exited with code -532459699 (0xe0434f4d).

----------------------------------------------------------------------------

reply awaited.

Thanks
Jul 7 '08 #5
Plater
7,872 Recognized Expert Expert
Looks like the results from the server don't come back in the http/1.1 standard.
(Possibly doesn't return ANY status line is my guess)
Jul 7 '08 #6

Sign in to post your reply or Sign up for a free account.

Similar topics

0
by: James Hong | last post by:
Help please, I try to sending an email from my html page using the java applet. but it give error on most of the PC only very few work, what is the error i make the java applet show as below ...
1
by: malborg | last post by:
I have simple form in PHP with two input types as text to input login name and password.PS: They use POST method. (index.php) The other script(logowanie.php) checks if login and password is...
3
by: Kenny | last post by:
I'm trying to retrieve the data off a form (survey.htm) and email the results back to me using CDO and ASP (survey.asp). I'm confused as to how to retrieve the form data from survey.htm and send...
2
by: Fatih BOY | last post by:
Hi, I want to send a report from a windows application to a web page like 'report.asp' Currently i can send it via post method with a context like local=En&Username=fatih&UserId=45&Firm=none...
9
by: eswanson | last post by:
I have a web page I need to post a file plus some other fields to it. How can I do this from a asp.net page. I know I can send individual fields to the other page, but how do I send a file to the...
2
by: Ryan | last post by:
Hi, I receive an access denied error (see below) when attempting to send an email with BodyFormat=MailFormat.Html from an asp.net page. Exactly the same code works fine in a console...
5
by: trig | last post by:
Please help! I am an ICT teacher at a secondary school and my year 12 (AS Level) group need to create a website where data can be sent from a form to a Microsoft Access database. I am trying...
2
by: nondos | last post by:
hi i have this html code that do search everytime i click on the button <FORM action=http://www.url.com/?s=somthing method=post><INPUT type=submit value="search" name=src> now i want to do...
2
by: anu b | last post by:
Now i am sending email to my friend using session variable... but my code is as below private bool SendEmail(string email) { try
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
0
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...
0
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
muto222
php
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.