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

Adam Tauno Williams awilliam at whitemice.org
Fri May 14 07:25:32 EDT 2010


On Fri, 14 May 2010, Andy York wrote:
> Does RESTful Service = Web Service?

Yes, it is essentially RPC over WebDAV.  SOAP & XML-RPC are easier, but 
whatever, some HTTP jockeys really get excited over managing lots of 
low-level stuff themselves.

> 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)

+1

Gtk# doesn't have anything to do with RPC, that is all just .NET.

> 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();

See!  Using an XML-RPC or SOAP proxy class is *SO* much easier it is 
unbelievable.

With REST you also need to perform POST (they even get that wrong), PUT, 
and DELETE requests.  I'd search the Internet for examples of 
communicating with WebDAV servers via C#/.NET since REST is pretty much 
WebDAV without any of the useful bits.


More information about the Gtk-sharp-list mailing list