First, I tried to connect external Rest API through console and was able to connect and send the data. Now, I am trying to consume the same in Plugin but no luck.
I have read so many blogs, was informed to change the isolation mode from sandbox to None. As we are using "ONLINE", I could not.
If any one has alternatives, Kindly, please let me know.
Thanks in Advance!
Code :
HttpWebRequest webrequest = (HttpWebRequest)WebRequest.Create("XXX");
webrequest.Method = "POST";
webrequest.ContentType = "application/json";
webrequest.Headers.Add("Authorization", "YYY");
string customer = "{\"isperson\":\"" + "false" + "\",\"companyname\":\"" + "Customer 2" + "\"}";
using (var streamWriter = new StreamWriter(webrequest.GetRequestStream()))
{
streamWriter.Write(customer);
streamWriter.Flush();
streamWriter.Close();
var httpResponse = (HttpWebResponse)webrequest.GetResponse();
using (var streamReader = new StreamReader(httpResponse.GetResponseStream()))
{
var result = streamReader.ReadToEnd();
}
}
INNER EXCEPTION : InnerException {"Request for the permission of type 'System.Net.WebPermission, System, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089' failed."} System.Exception
EXCEPTION MESSAGE : Insufficient permissions for setting the configuration section 'defaultProxy'