Reputation: 1568
I'm trying to send a json to a php page but result is always empty.
try
{
using (WebClient webclient = new WebClient())
{
webclient.Headers.Add("user-agent", "Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.2; .NET CLR 1.0.3705;)");
webclient.Headers.Add("Content-Type", "application/json");
webclient.Encoding = System.Text.Encoding.UTF8;
string result = await webclient.UploadStringTaskAsync(url,"POST",json);
if (debug)
Console.WriteLine(" => " + result); // array(0) { }
}
}
The json string is obtained with
string json = Newtonsoft.Json.JsonConvert.SerializeObject(searchModel);
And json output is
{"term":"test","local":null,"localLabel":null,"result":null,"resultLabel":null,"genre":null,"costumer":null}
My url target:
<?php echo var_dump($_POST); ?>
//doing $test="test" and adding $test inside var_dump shows the right value..
what i'm missing here?
Upvotes: 0
Views: 29