I have an requirement to pass a some values from mobile to server in a web service call and so I am planning to pass all the values in JSON format like the below
<
let qs = event.queryStringParameters;
const query = Object.keys(qs).map(key => key + '=' + qs[key]).join('&');
Send Json data string to a web address and get a result with method post
in C#
public string SendJsonToUrl(string Url, string StrJsonData)
{
if (Url == "" || StrJsonData == "") return "";
try
{
HttpWebRequest request = (HttpWebRequest)WebRequest.Create(Url);
request.Method = "POST";
request.ContentType = "application/json";
request.ContentLength = StrJsonData.Length;
using (var streamWriter = new StreamWriter(request.GetRequestStream()))
{
streamWriter.Write(StrJsonData);
streamWriter.Close();
var httpResponse = (HttpWebResponse)request.GetResponse();
using (var streamReader = new StreamReader(httpResponse.GetResponseStream()))
{
var result = streamReader.ReadToEnd();
return result;
}
}
}
catch (Exception exp)
{
throw new Exception("SendJsonToUrl", exp);
}
}
in PHP
<?php
$input = file_get_contents('php://input');
$json = json_decode($input ,true);
?>
& is a keyword for the next parameter like this ur?param1=1¶m2=2
so effectively you send a second param named R". You should urlencode
your string. Isn't POST an option?