The following is my code and it works to send data from C # to my REST API and this information is stored correctly in the database:
so I send the information from C #:
using (var WC = new WebClient())
{
WC.Headers[HttpRequestHeader.ContentType] = "application/json;charset=utf-8";
WC.Encoding = Encoding.UTF8;
var datajson = josnencode;
var response = WC.UploadString("http://www.mipaginaweb.mx/RegClient",datajson);
dynamic respuestatxt = JsonConvert.DeserializeObject(response);
string msjok = respuestatxt.mensaje;
MessageBox.Show(msjok,"Cliente Registrado",MessageBoxButtons.OK,MessageBoxIcon.Information);
}
Where "josnencode" is my serialized data in json format.
Data received from C # in json format in my API
if($_GET['url'] == "RegClient")
{
$json_string = file_get_contents("php://input");
$body = json_decode($json_string);
$nombre=$body->nombre;
$retorno = transaccion::InsertClient($nombre);
if ($retorno) {
echo json_encode(array('resultado' => 'OK','mensaje' => 'Cliente registrado exitosamente!'));
} else {
echo json_encode(array('resultado' => 'NONE','mensaje' => 'No se pudo registra el cliente'));
}
transactios.php
public function InsertClient($nombre)
{
$query = $sql ->prepare("INSERT INTO MiTabla(Nombre) VALUES(?)");
$query->bind_param('s',$nombre);
$query->execute();
}
Now how can I send an image (or several) following the same logic of what I already have? Taking into account that I can insert the database with what I show you ...
Thanks for your comments.