[Gtk-sharp-list] Newbee: How to perform a HttpRequest from a GTK# app?

Andy York andy at brdstudio.net
Fri May 14 06:35:00 EDT 2010


Does RESTful Service = Web Service? I can't keep all the abbreviations 
straight. Consuming a web service is identical to how you would do it 
with Windows.Forms. Here is an article that should set you in the right 
direction 
(http://www.codeproject.com/KB/webservices/MonoStockInformation.aspx)

Here is a simple article on the subject: 
(http://www.codeproject.com/KB/IP/DownloadClass.aspx?msg=3302029)

Last and probably least a simple stupid read/write, this should work but 
it was just slapped together quickly so your going to want to check it over.

bool blnEndOfFile = false;
HttpWebRequest wr = 
(HttpWebRequest)HttpWebRequest.Create("http://www.example.com/foobar.xml");
HttpWebResponse wsp = (HttpWebResponse)wr.GetResponse();
System.IO.Stream s = wsp.GetResponseStream();
FileStream fs = new FileStream("C:\Users\UserName\Downloads", 
FileMode.Create, FileAccess.Write);
long lgFileProgress = 0;
byte[] b = new byte[2048];
while (!blnEndOfFile)
{
     int n = s.Read(b, 0, b.Length);
     if (n > 0)
     {
         fs.Write(b, 0, n);
     }
     else
     {
         blnEndOfFile = true;
     }
}
s.Close();
fs.Close();

I hope this helps.

SpoodyGoon


On 5/14/2010 1:18 AM, cambiata wrote:
> RESTful service




More information about the Gtk-sharp-list mailing list