Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>You can't use <code>HttpClient</code> (yet!), but you can still use the <code>System.Net.HttpWebRequest</code> object, which does actually do what <code>HttpClient</code> can provide convenient wrappers for (especially when hitting up a Web API controller).</p> <p>Here's a sample from a current project I'm working on (it's using the monodroid port of <code>NewtonSoft.Json</code>, not the standard <code>System.Runtime.Serialization.Json</code>) :</p> <pre><code> private void AddARecord() { var cartesian = new Cartesian() { Description = "next item blah", X = 5, Y = 10, Z = 15, }; string json = JsonConvert.SerializeObject(cartesian); var request = new HttpWebRequest(new Uri(_url)) {ContentType = "application/json", Method = "POST"}; var sw = new StreamWriter(request.GetRequestStream(), System.Text.Encoding.ASCII); sw.Write(json); sw.Close(); request.BeginGetResponse(ProcessJsonResponseForSingleResult, request); } </code></pre> <p>...the Web API controller I'm hitting does something arbitrary, saves the object I just sent, and then tweaks the description so I know it works. Then it sends the tweaked object back... </p> <p>And then the callback <code>ProcessJsonResponseForSingleResult</code> looks like</p> <pre><code> private void ProcessJsonResponseForSingleResult(IAsyncResult ar) { var request = (HttpWebRequest)ar.AsyncState; var response = request.EndGetResponse(ar); using (var outputStream = new StreamReader(response.GetResponseStream(), System.Text.Encoding.ASCII)) { var jsonString = outputStream.ReadToEnd(); Log.Info("PJRFSR", string.Format("JSON string: {0} - deserialising...", jsonString)); var cartesian = JsonConvert.DeserializeObject&lt;Cartesian&gt;(jsonString); RunOnUiThread(() =&gt; UpdateUiTextView(cartesian.Description)); } } </code></pre> <p>Yeah, I know, it uses the BeginAsync/EndAsync pattern which I don't like any more either, but it does work if you just need to get something done.</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload