I'm sending a JSON post using C#. Everything is working fine if I hardcode the values directly in the request. But I want to send that in a form of variable, but is failing. I tried different ways and I couldn't find any solution. I'm trying to get the value from 'num' variable which is 172024 in the ID field, but in the response I'm getting the string as is, not the value.
Here is my code
static void Main(string[] args)
{
//Make a Json request
var httpWebRequest = (HttpWebRequest)WebRequest.Create("http://IPaddress/apibxe_json.php");
httpWebRequest.ContentType = "application/json";
httpWebRequest.Method = "POST";
using (var streamWriter = new StreamWriter(httpWebRequest.GetRequestStream()))
{
string num;
num = Convert.ToString("172024");
Console.WriteLine(num);
string json = "[ { \"connection\" : { \"PS\": \"99778\", \"pr\" : \"******\" }}, {\"execute\" : { \"name\" : \"NewAPI\", \"params\" : { \"Action\" : \"NEW\", \"ID\": \"$num\" , \"Dlr\" : \"&&&&&\"}}}]";
streamWriter.Write(json);
}
//Get the response
var httpResponse = (HttpWebResponse)httpWebRequest.GetResponse();
using (var streamReader = new StreamReader(httpResponse.GetResponseStream()))
{
var responseText = streamReader.ReadToEnd();
JArray jresponse = JArray.Parse(responseText);
Console.WriteLine(jresponse);
}
}