Hi
I am new to the c#, I am trying to develop an application which queries the website
http://patft.uspto.gov/netahtml/PTO/search-bool.html
and then the application fills the term1 field (which is given by user) and the field1 as the assignee name
I have written the following code but I am getting the exception: System.Net.WebException
the code is:
public Form2(TextBox t)
{
InitializeComponent();
label1.Text = t.Text;
StringBuilder sb = new StringBuilder();
byte[] buf = new byte[100000000];
try
{
string webpage_data = "Sect1=PTO2&Sect2=HITOFF&p=1&u=/netahtml/PTO/search-bool.html&r=0&f=S&l=50&TERM1=" + t.Text + "&FIELD1=ASNM&co1=AND&TERM2=&FIELD2=&d=PTXT";
// 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;
HttpWebResponse response = (HttpWebResponse)myRequest.GetResponse();
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);
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 stack trace is as follows:
'WindowsFormsApplication1.vshost.exe' (Managed): Loaded 'C:\Windows\assembly\GAC_32\mscorlib\2.0.0.0__b77a5c561934e089\mscorlib.dll'
'WindowsFormsApplication1.vshost.exe' (Managed): Loaded 'C:\Windows\assembly\GAC_MSIL\Microsoft.VisualStudio.HostingProcess.Utilities\9.0.0.0__b03f5f7f11d50a3a\Microsoft.VisualStudio.HostingProcess.Utilities.dll'
'WindowsFormsApplication1.vshost.exe' (Managed): Loaded 'C:\Windows\assembly\GAC_MSIL\System.Windows.Forms\2.0.0.0__b77a5c561934e089\System.Windows.Forms.dll'
'WindowsFormsApplication1.vshost.exe' (Managed): Loaded 'C:\Windows\assembly\GAC_MSIL\System\2.0.0.0__b77a5c561934e089\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.VisualStudio.HostingProcess.Utilities.Sync\9.0.0.0__b03f5f7f11d50a3a\Microsoft.VisualStudio.HostingProcess.Utilities.Sync.dll'
'WindowsFormsApplication1.vshost.exe' (Managed): Loaded 'C:\Windows\assembly\GAC_MSIL\Microsoft.VisualStudio.Debugger.Runtime\9.0.0.0__b03f5f7f11d50a3a\Microsoft.VisualStudio.Debugger.Runtime.dll'
'WindowsFormsApplication1.vshost.exe' (Managed): Loaded 'C:\Users\Siddharth\Documents\Visual Studio 2008\Projects\WindowsFormsApplication1\WindowsFormsApplication1\bin\Debug\WindowsFormsApplication1.vshost.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.DataSetExtensions\3.5.0.0__b77a5c561934e089\System.Data.DataSetExtensions.dll'
'WindowsFormsApplication1.vshost.exe' (Managed): Loaded 'C:\Windows\assembly\GAC_32\System.Data\2.0.0.0__b77a5c561934e089\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 0x15dc has exited with code 0 (0x0).
The thread 0x1154 has exited with code 0 (0x0).
The thread 0x1148 has exited with code 0 (0x0).
'WindowsFormsApplication1.vshost.exe' (Managed): Loaded 'C:\Users\Siddharth\Documents\Visual Studio 2008\Projects\WindowsFormsApplication1\WindowsFormsApplication1\bin\Debug\WindowsFormsApplication1.exe', Symbols loaded.
'WindowsFormsApplication1.vshost.exe' (Managed): Loaded 'C:\Windows\assembly\GAC_MSIL\System.Configuration\2.0.0.0__b03f5f7f11d50a3a\System.Configuration.dll'
A first chance exception of type 'System.InvalidOperationException' occurred in System.dll
A first chance exception of type 'System.InvalidOperationException' occurred in WindowsFormsApplication1.exe
An unhandled exception of type 'System.InvalidOperationException' occurred in WindowsFormsApplication1.exe
Additional information: This property cannot be set after writing has started.
The thread 'vshost.RunParkingWindow' (0x1710) has exited with code 0 (0x0).
The program '[4280] WindowsFormsApplication1.vshost.exe: Managed' has exited with code -532459699 (0xe0434f4d).
Any help would be highly appreciated.
Thanks