Last active
January 3, 2016 13:49
-
-
Save brainwipe/8472430 to your computer and use it in GitHub Desktop.
For S-O question: This method returns 204.
This file contains hidden or 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.Text; | |
using System.Threading.Tasks; | |
using System.Net.Http; | |
using System.Net.Http.Headers; | |
namespace Client | |
{ | |
class Program | |
{ | |
static void Main(string[] args) | |
{ | |
Task.WaitAll(Go()); // block while the task completes | |
} | |
static async Task<HttpResponseMessage> Go() | |
{ | |
string serviceUrl = "http://localhost:4097/api/test/KillPerson"; | |
var httpClient = new HttpClient { BaseAddress = new Uri("http://localhost:4097") }; | |
httpClient.DefaultRequestHeaders.Accept.Add(new MediaTypeWithQualityHeaderValue("application/json")); | |
var httpContent = new StringContent("{a: 'b'}", Encoding.UTF8, "application/json"); | |
var response = await httpClient.PostAsync(serviceUrl, httpContent).ConfigureAwait(false); | |
response.EnsureSuccessStatusCode(); | |
return response; | |
} | |
} |
This file contains hidden or 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; | |
using System.Net.Http; | |
using System.Web.Http; | |
namespace WebAPITest.Areas.Test | |
{ | |
public class TestController : ApiController | |
{ | |
// POST api/<controller> | |
[ActionName("KillPerson")] | |
[HttpPost] | |
public void Post([FromBody]string value) | |
{ | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment