DRAG DROP
You are developing a .NET application that uses the HttpClient type to access an ASP.NET Web API
application.You need to add a header to specify that data is returned as JSON. You have the following code:
Which code segments should you include in Target 1 and Target 2 to complete the code? (To answer,
drag the appropriate code segments to the correct targets in the answer area. Each code segment may
be used once, more than once, or not at all. You may need to drag the split bar between panes or scroll
to view content)
Accept: application/json
why Accept? if data is returned from server you need to specify Content-Type header!
The content type is a header of the content, not of the request.
Also possible:
HttpClient client = new HttpClient();
client.BaseAddress = new Uri(“http://example.com/”);
client.DefaultRequestHeaders
.Accept
.Add(new MediaTypeWithQualityHeaderValue(“application/json”));//ACCEPT header
HttpRequestMessage request = new HttpRequestMessage(HttpMethod.Post, “relativeAddress”);
request.Content = new StringContent(“{\”name\”:\”John Doe\”,\”age\”:33}”,
Encoding.UTF8,
“application/json”);//CONTENT-TYPE header
client.SendAsync(request)
.ContinueWith(responseTask =>
{
Console.WriteLine(“Response: {0}”, responseTask.Result);
});
Accept is correct
You need to add a header to specify that data is returned as JSON. You have the following code
Returned from server to client and you guys say accept? WTF is wrong with you guys
maybe im an idiot but i dont understand this
http://stackoverflow.com/questions/10679214/how-do-you-set-the-content-type-header-for-an-httpclient-request
Accept for requestheader
Secretion, this is an instance of HttpClient, so we assume we do a request inside the object client to some server… so WTF is wrong with you guy 😉 we are on the client side not the server side within this code…