Created
December 8, 2014 22:09
-
-
Save andrewconnell/300218c7bddd4c870451 to your computer and use it in GitHub Desktop.
XML vs. JSON Serialization in Server Side Code - Snippet 1
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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