J
Jeffery Tyree
All I would like is one example of working code that does nothing more than
submit a search criteria to Google and print to console the resulting page
of found items. To make it easier, below is my code. Simply correct it in
place so that I may copy/paste it back into the IDE and run it. Please do
not tell me to do net sniff comparisons or make sure I have the right
control values. If I knew these things I wouldn't be here asking, right?
Again, please simply correct my code in place so that it works and I (and
others) have an actual working example. Many many TIA.
FYI: the code is taken originally from the .NET Framework documentation
using System;
using System.Net;
using System.Text;
using System.IO;
class ClientGet
{
public static void Main(string[] args)
{
Uri site = new Uri("http://www.google.com");
WebRequest wReq = WebRequest.Create(site);
wReq.Method = "Post";
wReq.ContentType = "application/x-www-form-urlencoded" ;
string data = "q=starfish&btnG=click";
byte[] buffer = Encoding.UTF8.GetBytes (data);
wReq.ContentLength = buffer.Length ;
Stream reqStream = wReq.GetRequestStream ();
reqStream.Write (buffer, 0, buffer.Length);
reqStream.Flush ();
reqStream.Close ();
WebResponse wRes = wReq.GetResponse();
Stream respStream = wRes.GetResponseStream ();
StreamReader reader = new StreamReader(respStream, Encoding.ASCII);
String respHTML = reader.ReadToEnd();
Console.WriteLine(respHTML);
Console.ReadLine();
wRes.Close();
}
}
submit a search criteria to Google and print to console the resulting page
of found items. To make it easier, below is my code. Simply correct it in
place so that I may copy/paste it back into the IDE and run it. Please do
not tell me to do net sniff comparisons or make sure I have the right
control values. If I knew these things I wouldn't be here asking, right?
Again, please simply correct my code in place so that it works and I (and
others) have an actual working example. Many many TIA.
FYI: the code is taken originally from the .NET Framework documentation
using System;
using System.Net;
using System.Text;
using System.IO;
class ClientGet
{
public static void Main(string[] args)
{
Uri site = new Uri("http://www.google.com");
WebRequest wReq = WebRequest.Create(site);
wReq.Method = "Post";
wReq.ContentType = "application/x-www-form-urlencoded" ;
string data = "q=starfish&btnG=click";
byte[] buffer = Encoding.UTF8.GetBytes (data);
wReq.ContentLength = buffer.Length ;
Stream reqStream = wReq.GetRequestStream ();
reqStream.Write (buffer, 0, buffer.Length);
reqStream.Flush ();
reqStream.Close ();
WebResponse wRes = wReq.GetResponse();
Stream respStream = wRes.GetResponseStream ();
StreamReader reader = new StreamReader(respStream, Encoding.ASCII);
String respHTML = reader.ReadToEnd();
Console.WriteLine(respHTML);
Console.ReadLine();
wRes.Close();
}
}