Ejemplo proyecto de consola en C# para enviar y recibir peticiones REST de un origen PHP
static void Main(string[] args)
{
string URL = "http://localhost/sitio/archivo.php";
WebClient webClient = new WebClient();
NameValueCollection formData = new NameValueCollection();
formData["username"] = "testuser";
formData["password"] = "mypassword";
byte[] responseBytes = webClient.UploadValues(URL, "POST", formData);
string responsefromserver = Encoding.UTF8.GetString(responseBytes);
Console.WriteLine(responsefromserver);
// Leer Json
JArray a = JArray.Parse(responsefromserver);
// el cero es indice del arreglo que es una fila, se debe convertir a list
Console.WriteLine("**** " + a[0]["Campo1"]);
Console.WriteLine("**** " + a[0]["Campo2"]);
Console.ReadKey();
webClient.Dispose();
}
|