Click here to Skip to main content
15,884,933 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I want to access a webpage & store the contents of the webpage into a database this is the code I have tried for reading the contents of the webpage
C#
public static WebClient wClient = new WebClient();
   public static TextWriter textWriter;
   public static String readFromLink()
   {
     string url = "http://www.ncedc.org/cgi-bin/catalog-search2.pl";
       HttpWebRequest webRequest = WebRequest.Create(url) as HttpWebRequest;
       webRequest.Method = "POST";
       System.Net.WebClient client = new System.Net.WebClient();
       byte[] data = client.DownloadData(url);
       string html = System.Text.Encoding.UTF8.GetString(data);
       return html;
   }
   public static bool WriteTextFile(String fileName, String t)
   {

       try
       {
           textWriter = new StreamWriter(fileName);
       }
       catch (Exception)
       {
           return false;
           Console.WriteLine("Data Save Unsuccessful: Could Not create File");
       }

       try
       {
           textWriter.WriteLine(t);
       }
       catch (Exception)
       {
           return false;
           Console.WriteLine("Data Save UnSuccessful: Could Not Save Data");
       }
       textWriter.Close();
       return true;
       Console.WriteLine("Data Save Successful");
   }
   static void Main(string[] args)
   {
       String saveFile = "E:/test.txt";
       String reSultString = readFromLink();
       WriteTextFile(saveFile, reSultString);
       Console.ReadKey();
   }

but this code gives me an o/p as- This script should be referenced with a METHOD of POST. REQUEST_METHOD=GET

please tell me how to resolve this
Posted
Updated 9-Jul-13 1:44am
v2
Comments
Thanks7872 9-Jul-13 7:47am    
Dont you get solution at http://stackoverflow.com/questions/17539756/how-to-read-content-from-webpage?

Is there still any issues?

1 solution

As advised on SO (http://stackoverflow.com/questions/8222092/sending-http-post-with-system-net-webclient[^]) you can use the WebClient class' method UploadValues(...)[^].

Regards,
— Manfred
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900