Which code segments should you include in Target 1 and Target 2 to complete the code?

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)

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)

Answer:



Leave a Reply 8

Your email address will not be published. Required fields are marked *


T

T

Accept: application/json

sfasdgf

sfasdgf

why Accept? if data is returned from server you need to specify Content-Type header!

R

R

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);
});

nex-54

nex-54

Accept is correct

Secretion

Secretion

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

pir

pir

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…