[MonoTouch] PUT call to server using WebRequest

2012-08-12 Thread Phil Cockfield
Hello!

I'm using the *HttpWebRequest *to do a PUT on my server.  The web-server is
Node.js.  The code is very by the book standard stuff:


// Prepare the data.
  var dataText = data.ToString();
  var byteArray = dataText.ToByteArray();

  // Setup the web-request.
  var req = WebRequest.Create(url);
  req.Method = PUT;
  req.ContentType = Content-Type: application/json; charset=utf-8;
  req.ContentLength = byteArray.Length;

  // Process the stream.
  var dataStream = req.*GetRequestStream*();
  dataStream.Write(byteArray, 0, byteArray.Length);
  dataStream.Close();



The problem is, when I call *GetRequestStream* it issues the request to the
server and the response is complete before the next line (dataStream.Write)
executes.  As a result no data is actually sent.  It's like the stream
prematurely flushes upon creation.  In fact, I didn't think it was supposed
to call the server at all until *GetResponse* was invoked.

Am I doing something dumb here?  Or, is it something with the way Node is
behaving (that would be weird if it were).  Or is HttpWebRequest flakey?

This works if I use *WebClient*.  But I need HttpStatus codes - and my
understanding is you can't get at those from *WebClient*.  (If you can, I
can't find them anywhere! :-))

Anyone else seeing weirdness with *HttpWebRequest*?

-- 
*Phil *Cockfield
___
MonoTouch mailing list
MonoTouch@lists.ximian.com
http://lists.ximian.com/mailman/listinfo/monotouch


Re: [MonoTouch] PUT call to server using WebRequest

2012-08-12 Thread Jason Awbrey
I believe you can get WebClient status codes by catching WebException and
looking at it's Response.StatusCode

assuming you're only interested in failure status codes, this might work
for you

On Sun, Aug 12, 2012 at 8:34 AM, Phil Cockfield p...@cockfield.net wrote:

 Hello!

 I'm using the *HttpWebRequest *to do a PUT on my server.  The web-server
 is Node.js.  The code is very by the book standard stuff:


 // Prepare the data.
   var dataText = data.ToString();
   var byteArray = dataText.ToByteArray();


   // Setup the web-request.

   var req = WebRequest.Create(url);
   req.Method = PUT;
   req.ContentType = Content-Type: application/json; charset=utf-8;
   req.ContentLength = byteArray.Length;

   // Process the stream.
   var dataStream = req.*GetRequestStream*();
   dataStream.Write(byteArray, 0, byteArray.Length);
   dataStream.Close();



 The problem is, when I call *GetRequestStream* it issues the request to
 the server and the response is complete before the next line (dataStream.
 Write) executes.  As a result no data is actually sent.  It's like the
 stream prematurely flushes upon creation.  In fact, I didn't think it was
 supposed to call the server at all until *GetResponse* was invoked.

 Am I doing something dumb here?  Or, is it something with the way Node is
 behaving (that would be weird if it were).  Or is HttpWebRequest flakey?

 This works if I use *WebClient*.  But I need HttpStatus codes - and my
 understanding is you can't get at those from *WebClient*.  (If you can, I
 can't find them anywhere! :-))

 Anyone else seeing weirdness with *HttpWebRequest*?

 --
 *Phil *Cockfield




 ___
 MonoTouch mailing list
 MonoTouch@lists.ximian.com
 http://lists.ximian.com/mailman/listinfo/monotouch


___
MonoTouch mailing list
MonoTouch@lists.ximian.com
http://lists.ximian.com/mailman/listinfo/monotouch


Re: [MonoTouch] PUT call to server using WebRequest

2012-08-12 Thread Phil Cockfield
Ok. Good call - will revert to web client. 

Wired MS prioritized the HTTP status code so lowly I'm the API. 

I wonder if what I saw with HttpRequest is a bug. Probably not,
 because WebClient uses HttpRequest (I think), so perhaps some configuration 
setup I was getting wrong before opening the stream. 

Sent from my iPhone

On 13/08/2012, at 2:30 AM, Jason Awbrey ja...@awbrey.net wrote:

 I believe you can get WebClient status codes by catching WebException and 
 looking at it's Response.StatusCode
 
 assuming you're only interested in failure status codes, this might work for 
 you
 
 On Sun, Aug 12, 2012 at 8:34 AM, Phil Cockfield p...@cockfield.net wrote:
 Hello!
 
 I'm using the HttpWebRequest to do a PUT on my server.  The web-server is 
 Node.js.  The code is very by the book standard stuff:
 
 
 // Prepare the data.
 
   var dataText = data.ToString();
 
 
   var byteArray = dataText.ToByteArray();
 
 
 
 
   // Setup the web-request.
 
   var req = WebRequest.Create(url);
 
 
   req.Method = PUT;
 
 
   req.ContentType = Content-Type: application/json; charset=utf-8;
 
 
   req.ContentLength = byteArray.Length;
 
 
 
   // Process the stream.
 
 
   var dataStream = req.GetRequestStream();
 
 
   dataStream.Write(byteArray, 0, byteArray.Length);
 
 
   dataStream.Close();
 
 
 
 
 The problem is, when I call GetRequestStream it issues the request to the 
 server and the response is complete before the next line (dataStream.Write) 
 executes.  As a result no data is actually sent.  It's like the stream 
 prematurely flushes upon creation.  In fact, I didn't think it was supposed 
 to call the server at all until GetResponse was invoked.
 
 Am I doing something dumb here?  Or, is it something with the way Node is 
 behaving (that would be weird if it were).  Or is HttpWebRequest flakey?
 
 This works if I use WebClient.  But I need HttpStatus codes - and my 
 understanding is you can't get at those from WebClient.  (If you can, I can't 
 find them anywhere! :-))
 
 Anyone else seeing weirdness with HttpWebRequest?
 
 -- 
 Phil Cockfield
 
 
 
 
 ___
 MonoTouch mailing list
 MonoTouch@lists.ximian.com
 http://lists.ximian.com/mailman/listinfo/monotouch
 
 
___
MonoTouch mailing list
MonoTouch@lists.ximian.com
http://lists.ximian.com/mailman/listinfo/monotouch