473,545 Members | 1,779 Online
Bytes | Software Development & Data Engineering Community
+ 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.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
  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:

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

'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
Jul 7 '08 #1
5 12805
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.WebE xception at the line

HttpWebResponse response = (HttpWebRespons e)myRequest.Get Response();

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.webe xception, 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 :
----------------------------------------------------------------------------
'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 0x9d4 has exited with code 0 (0x0).
The thread 0x10b8 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.
A first chance exception of type 'System.IO.File NotFoundExcepti on' occurred in mscorlib.dll
'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.ObjectD isposedExceptio n' occurred in System.dll
A first chance exception of type 'System.Net.Web Exception' occurred in System.dll
An unhandled exception of type 'System.Net.Web Exception' occurred in System.dll

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

The thread 0x1210 has exited with code 0 (0x0).
The program '[4712] WindowsFormsApp lication1.vshos t.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
9858
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 ********************************** package Celcom.Client;
1
10890
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 correct and displays: "You are loged in." or "Your password or login name is incorrect." I'm trying to login using IdHTTP from Indy components. But in...
3
3015
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 it using survey.asp. Below is a sample ASP script that I found on ASPFAQ.com and it works fine, but now how do I grab the info from a form and...
2
20735
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 But the problem occures when i want to send a data with & sign (i.e: Firm=F&B). I try to solve this problem with using boundary, but i failed. Any...
9
3129
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 other page, or is there something else like a stream which will be like a file. I am attempting to get a way from writing out a file and then...
2
3480
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 application, and also succeeds from the asp.net page with BodyFormat=MailFormat.Text. I've recently upgraded from W2K SP4 to WinXP SP2 and am using .Net...
5
6075
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 to do this in my own time and then hopefully teach them how to do it. I have installed IIS on my machine and have followed a few web
2
3215
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 the same thing but in vb.net any idea how to do it? notice to the way the data send to the server in the html code
2
18161
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
7459
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main...
0
7653
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. ...
0
7803
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that...
1
7411
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For...
1
5322
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes...
0
3444
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 last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in...
0
3439
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
1871
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
1
1012
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.