I have a REST API with a function that returns a number (folio for me) and adds 1 and so on, if I execute that function from Postam using the API URL, it returns what I want, until here everything very well. Now as I command to execute that function from c # ?, I would not pass parameters to it, I just want to execute the function and the returned response is a json_encode (message). I understand that it can be done with webclient downloadstring (url api) but it does not return the json, it only returns null. Any serious help welcome. Thanks again.
Here's the code in PHP:
else if($_GET['url'] == "folio")
{
$respuesta = Clientes::ObtenerFolio();
$contenedor = array();
if($respuesta)
{
$contenedor["resultado"]="OK";
$contenedor["datos"]= $respuesta;
echo json_encode($contenedor);
}
else
{
echo json_encode(array(
"resultado" => 'NONE',
"mensaje" =>'No se pudo asignar folio al cliente'
));
}
This is from C # winforms:
try
{
string responsebody;
HttpClient cliente = new HttpClient();
HttpResponseMessage response = await cliente.GetAsync("http://www.mipagina.mx/WebService/folio");
response.EnsureSuccessStatusCode();
responsebody = await response.Content.ReadAsStringAsync();
dynamic datosdes = JsonConvert.DeserializeObject(responsebody);
string mjsserver = datosdes.resultado;
string msjservernot = datosdes.datos;
}
catch (Exception ex)
{
MessageBox.Show(ex.Message);
}