I need to have a POST link request, so I also get the json in php .
This is the test code in php
<?php
if(isset($_POST['request']))
{
echo $jsonret = '{"request":"sim","name":"'.$_POST['request'].'"}';
}
else
{
echo $jsonret = '{"request":"não","name":"invalid"}';
}
?>
This was my attempt at C # , like asynchronous methods should always be of the void type, I tried using a static variable , but it still does not change the string .
Note: The request works without a problem.
private void button1_Click(object sender, EventArgs e)
{
RequestJson();
MessageBox.Show(retornojson);
}
static string retornojson = "nulo";
public async void RequestJson()
{
string req = "enviado";
//url do arquivo
string URL = "http://localhost/testjsonreturn";
var myHttpClient = new HttpClient();
//idusuario
var formContent = new FormUrlEncodedContent(new[]
{
new KeyValuePair<string, string>("request", req)
});
var request = await myHttpClient.PostAsync(URL, formContent);
retornojson = request.ToString();
}