Created
February 1, 2019 20:07
-
-
Save darrelmiller/64e23b5805231e464e58d36bc7e7c977 to your computer and use it in GitHub Desktop.
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
using System; | |
using System.Collections.Generic; | |
using System.Linq; | |
using System.Net.Http; | |
using System.Net.Http.Headers; | |
using System.Text; | |
using System.Threading.Tasks; | |
namespace ConsoleApp10 | |
{ | |
class Program | |
{ | |
static void Main(string[] args) | |
{ | |
var httpClient = new HttpClient(); | |
httpClient.SendAsync( | |
CreateRequest(HttpMethod.Get, new Uri("https://bing.com")) | |
.WithAccept("application/json")); | |
} | |
public static HttpRequestMessage CreateRequest(HttpMethod method, Uri requestUrl) | |
{ | |
return new HttpRequestMessage() | |
{ | |
Method = method, | |
RequestUri = requestUrl | |
}; | |
} | |
} | |
public static class HttpRequestMessageExtensions { | |
public static HttpRequestMessage WithAccept(this HttpRequestMessage hrm, string mediaType) | |
{ | |
hrm.Headers.Accept.Add(new MediaTypeWithQualityHeaderValue(mediaType)); | |
return hrm; | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment