PrepAway - Latest Free Exam Questions & Answers

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)

PrepAway - Latest Free Exam Questions & Answers

Answer:

9 Comments on “Which code segments should you include in Target 1 and Target 2 to complete the code?

    1. R says:

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




      2



      0
  1. Secretion says:

    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




    0



    2
    1. pir says:

      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…




      3



      0

Leave a Reply