.NET Web API CORS PreFlight Request

You can add a handler to deal with this type of request. Create a class derive from “DelegatingHandler”: public class PreflightRequestsHandler : DelegatingHandler { protected override Task<HttpResponseMessage> SendAsync(HttpRequestMessage request, CancellationToken cancellationToken) { if (request.Headers.Contains(“Origin”) && request.Method.Method.Equals(“OPTIONS”)) { var response = new HttpResponseMessage { StatusCode = HttpStatusCode.OK }; // Define and add values to variables: origins, … Read more

Body of Http.DELETE request in Angular2

The http.delete(url, options) does accept a body. You just need to put it within the options object. http.delete(‘/api/something’, new RequestOptions({ headers: headers, body: anyObject })) Reference options interface: https://angular.io/api/http/RequestOptions UPDATE: The above snippet only works for Angular 2.x, 4.x and 5.x. For versions 6.x onwards, Angular offers 15 different overloads. Check all overloads here: https://angular.io/api/common/http/HttpClient#delete … Read more

Javascript: Fetch DELETE and PUT requests

Here is a fetch POST example. You can do the same for DELETE. function createNewProfile(profile) { const formData = new FormData(); formData.append(‘first_name’, profile.firstName); formData.append(‘last_name’, profile.lastName); formData.append(’email’, profile.email); return fetch(‘http://example.com/api/v1/registration’, { method: ‘POST’, body: formData }).then(response => response.json()) } createNewProfile(profile) .then((json) => { // handle success }) .catch(error => error);

HttpDelete with body

Have you tried overriding HttpEntityEnclosingRequestBase as follows: import org.apache.http.client.methods.HttpEntityEnclosingRequestBase; import java.net.URI; import org.apache.http.annotation.NotThreadSafe; @NotThreadSafe class HttpDeleteWithBody extends HttpEntityEnclosingRequestBase { public static final String METHOD_NAME = “DELETE”; public String getMethod() { return METHOD_NAME; } public HttpDeleteWithBody(final String uri) { super(); setURI(URI.create(uri)); } public HttpDeleteWithBody(final URI uri) { super(); setURI(uri); } public HttpDeleteWithBody() { super(); } } … Read more