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:
------------------------------------------------------------------------------------------------
[code=c#]
public Form2(TextBox t)
{
InitializeCompo nent();
label1.Text = t.Text;
StringBuilder sb = new StringBuilder() ;
byte[] buf = new byte[100000000];
try
{
string webpage_data = t.Text + "&FIELD1=AS NM";
// string webpage_data = "TERM1=" + t.Text + "&FIELD1=AS NM";
// 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.GetByt es(webpage_data );
// webpage = webpage + "?" + webpage_data;
HttpWebRequest myRequest = (HttpWebRequest )WebRequest.Cre ate(webpage);
myRequest.Crede ntials = CredentialCache .DefaultCredent ials;
myRequest.Conte ntLength = data.Length;
myRequest.Metho d = "GET";
myRequest.Conte ntType = "applicatio n/x-www-form-urlencoded";
myRequest.Conte ntLength = data.Length;
Stream newStream = myRequest.GetRe questStream();
newStream.Write (data, 0, data.Length);
HttpWebResponse response = (HttpWebRespons e)myRequest.Get Response();
Stream receive_stream = response.GetRes ponseStream();
StreamReader read_stream = new StreamReader(re ceive_stream, Encoding.UTF8);
string str = read_stream.Rea dToEnd();
newStream.Close ();
// response.GetRes ponseStream(rea d_stream.ReadTo End());
response.Close( );
read_stream.Clo se();
richTextBox1.Te xt = str;
}
catch (Exception)
{
throw;
}
}
[/code]
---------------------------------------------------------------------------------------------------------------------------------------------------
and the log at the output tab is as follows:
---------------------------------------------------------------------------------------------------------------------------------------------------
-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
Thanks
Reply awaited
Sid
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:
------------------------------------------------------------------------------------------------
[code=c#]
public Form2(TextBox t)
{
InitializeCompo nent();
label1.Text = t.Text;
StringBuilder sb = new StringBuilder() ;
byte[] buf = new byte[100000000];
try
{
string webpage_data = t.Text + "&FIELD1=AS NM";
// string webpage_data = "TERM1=" + t.Text + "&FIELD1=AS NM";
// 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.GetByt es(webpage_data );
// webpage = webpage + "?" + webpage_data;
HttpWebRequest myRequest = (HttpWebRequest )WebRequest.Cre ate(webpage);
myRequest.Crede ntials = CredentialCache .DefaultCredent ials;
myRequest.Conte ntLength = data.Length;
myRequest.Metho d = "GET";
myRequest.Conte ntType = "applicatio n/x-www-form-urlencoded";
myRequest.Conte ntLength = data.Length;
Stream newStream = myRequest.GetRe questStream();
newStream.Write (data, 0, data.Length);
HttpWebResponse response = (HttpWebRespons e)myRequest.Get Response();
Stream receive_stream = response.GetRes ponseStream();
StreamReader read_stream = new StreamReader(re ceive_stream, Encoding.UTF8);
string str = read_stream.Rea dToEnd();
newStream.Close ();
// response.GetRes ponseStream(rea d_stream.ReadTo End());
response.Close( );
read_stream.Clo se();
richTextBox1.Te xt = str;
}
catch (Exception)
{
throw;
}
}
[/code]
---------------------------------------------------------------------------------------------------------------------------------------------------
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).
'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
Comment