Skip to content

Instantly share code, notes, and snippets.

@brainwipe
Last active January 3, 2016 13:49
Show Gist options
  • Save brainwipe/8472430 to your computer and use it in GitHub Desktop.
Save brainwipe/8472430 to your computer and use it in GitHub Desktop.
For S-O question: This method returns 204.
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;
}
}
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