Skip to content

Instantly share code, notes, and snippets.

@andrewconnell
Created December 8, 2014 22:09
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save andrewconnell/300218c7bddd4c870451 to your computer and use it in GitHub Desktop.
Save andrewconnell/300218c7bddd4c870451 to your computer and use it in GitHub Desktop.
XML vs. JSON Serialization in Server Side Code - Snippet 1
HttpClient client = new HttpClient();
// create the endpoint
StringBuilder requestUri = new StringBuilder(ServiceResourceId)
.Append("/_api/web/lists/getbytitle('Tasks')/items")
.Append("?$select=Id,Title,Status,Priority,AssignedTo/Name&$expand=AssignedTo");
// crete the request
HttpRequestMessage request = new HttpRequestMessage(HttpMethod.Get, requestUri.ToString());
// add request headers to authenticate & request XML from the service
request.Headers.Accept.Add(new MediaTypeWithQualityHeaderValue("application/xml"));
request.Headers.Authorization = new AuthenticationHeaderValue("Bearer", await GetAccessToken());
// execute the request & get the response back as a string
HttpResponseMessage response = await client.SendAsync(request);
string responseString = await response.Content.ReadAsStringAsync();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment