问题
I have defined a route in WordPress using register_rest_route
, this is set as a route that accepts only POST requests:
register_rest_route( 'myNamespace', '/myRoute/', array(
'methods' => 'POST',
'callback' => 'myCallbackFunction',
) );
Making a POST request to this route using Postman returns the result I expect. However, making a request from a C# application using either System.Net.Http.HttpClient
or System.Net.HttpWebRequest
I receive a 404 response.
When I change my register_rest_route
to accept GET requests, using the code below, my request is received, but fails because I need values posted in the body of the request.
register_rest_route( 'myNamespace', '/myRoute/', array(
'methods' => 'GET',
'callback' => 'myCallbackFunction',
) );
This is extremely peculiar and I cannot figure out why making the request from a C# application converts a HttpPost to a HttpGet request, but works perfectly fine when making the request from Postman.
I'm using .NET 4.8 SDK for my C# application and WordPress 5.3.2 for WordPress.
Right now I cannot figure out where the issue lies. At first I thought it was an issue with my C# application, so I changed the request tools from HttpWebRequest to HttpClient, but that did not fix the issue. Then I thought it was an issue with the PHP side of things, but Postman works fine.
I don't understand how the request method is changing in transit?
来源:https://stackoverflow.com/questions/59687853/post-request-changed-to-get-request-when-making-a-request-from-c-sharp-to-wordpr