RE: Unable to integrate NAV 2009 with 3rd party portal via API integration
public async Task<string> PostJsonData(JObject jsonObject, string ASP_URL, string CID, string CSR)
{
ServicePointManager.SecurityProtocol = SecurityProtocolType.Tls12;
ServicePointManager.Expect100Continue = true;
ServicePointManager.DefaultConnectionLimit = 9999;
var RequestJsonData = new StringContent(jsonObject.ToString(), Encoding.UTF8, "application/json");
try
{
using (HttpClient client = new HttpClient())
{
client.DefaultRequestHeaders.Accept.Add(new MediaTypeWithQualityHeaderValue("application/json"));
client.DefaultRequestHeaders.Add("gspappid", CID);
client.DefaultRequestHeaders.Add("gspappsecret", CSR);
string json = JsonConvert.SerializeObject(jsonObject);
StringContent JsonData = new StringContent(json, Encoding.UTF8, "application/json");
using (HttpResponseMessage response = client.PostAsync(Uri.EscapeUriString(ASP_URL.Trim().ToString()), JsonData).Result)
{
using (HttpContent Res = response.Content)
{
string resData = await Res.ReadAsStringAsync();
return resData.ToString();
}
}
}
}
catch (Exception Ex)
{
return Ex. Message;
}
}