I'm sending a JSON message from a C# client to a PHP server.
The C# client code is as follows:
private String baseUrl = null;
private String clientId = null;
private static readonly HttpClient client = new HttpClient();
private Task<string> Send(string method, Dictionary<string, string> metadata)
{
ServicePointManager.ServerCertificateValidationCallback = new
RemoteCertificateValidationCallback
(
delegate { return true; }
);
String jsonRequest = "{\"method\":\"checkLicence\"}";
StringContent content = new StringContent(jsonRequest, Encoding.UTF8, "application/json");
client.DefaultRequestHeaders.Add("CLIENT_ID", clientId);
String clientSecret = encodeClientSecret(clientId);
client.DefaultRequestHeaders.Add("CLIENT_SECRET", clientSecret);
var result = client.PostAsync(baseUrl + "/api", content);
HttpResponseMessage response = result.Result;
return response.Content.ReadAsStringAsync();
}
On the server-side, the PHP/Symfony endpoint is as follows:
/**
* @Route("/api", name="api")
*/
public function api(Request $request) {
$this->checkAuth();
$params = array();
$content = $request->getContent();
}
by PHP debugging, I find that the $content variable is empty when I receive this request. Why does it not contain the JSON string?
EDIT: to shed a bit more light on this - using Wireshark I can observe it seems my PHP server accepts the original POST request, and responds with a 302 (moved) response, and then somehow the redirect (now GET) request arrives at my /api endpoint, and has no content (because it's a redirect?)
Request?Requestin your PHP code is a user-defined class?Requestrefers to the Symfony classSymfony\Component\HttpFoundation\Request