Author Message
sivasubramanian2
Joined: Jul 30, 2010
Messages: 4
Offline
Team,

We are having a clarification related to Calling Campaign Management REST APIs using C#.

POM Version: 3.1.1

With POSTMAN, we are able to trigger the methods and getting the response for the request. But while we trying to invoke the same using C#, we are getting 403 Forbidden Exception. This is happening for both GET and POST Methods.

Could you please help us on this.

Please find below the snippets:

GET Invocation:
bool bResult1 = GET("https://192.168.31.175/VP_POM_Service/v2/globalconfig/name/WeekEndDays","siva","siva@123", out postBody);

POST Invocation:

string WSURL = "https://192.168.31.175/VP_POM_Service/v2/campaigns";
Zoneepmlist zoneepmlist = new Zoneepmlist("default", new string[] { "EPM" });
Zoneepmlist[] arrayZoneepmlist = new Zoneepmlist[] { zoneepmlist };
Campaign reqBody = new Campaign(campaignName, campaignDescription, "InfiniteWithoutContacts", campaignStrategy, arrayZoneepmlist, "false");
string json = JsonConvert.SerializeObject(reqBody);
string postBody = string.Empty;
//log.Debug("[SetTwilioRecordingDetails] URL = " + WSURL + " Request " + json);
bool bResult = POST(WSURL, json, out postBody);
var Result = JsonConvert.DeserializeObject<CampaignResponse>(postBody);
//log.Debug("[SetTwilioRecordingDetails] Response - status is " + Result.result);

Console.WriteLine(Result.campaignID);


public static bool POST(string url, string jsonContent, out string ResponseBody)
{
bool returnValue = false;
ResponseBody = string.Empty;
//log.Debug("[POST] URL = " + url + "; Input = " + jsonContent);

ServicePointManager.Expect100Continue = true;
ServicePointManager.ServerCertificateValidationCallback = new RemoteCertificateValidationCallback( delegate { return true; } );
ServicePointManager.SecurityProtocol = SecurityProtocolType.Tls12;

HttpWebRequest request = (HttpWebRequest)WebRequest.Create(url);
request.Method = "POST";

System.Text.UTF8Encoding encoding = new System.Text.UTF8Encoding();
Byte[] byteArray = encoding.GetBytes(jsonContent);

request.ContentLength = byteArray.Length;
request.ContentType = @"application/json";
request.Credentials = new NetworkCredential("siva", "siva@123");
request.UserAgent = "Code Sample Web Client";
using (Stream dataStream = request.GetRequestStream())
{
dataStream.Write(byteArray, 0, byteArray.Length);
}
try
{
using (HttpWebResponse response = (HttpWebResponse)request.GetResponse())
{
Stream dataStream = response.GetResponseStream();
StreamReader reader = new StreamReader(dataStream);
string strResponse = reader.ReadToEnd();
//log.Debug("[POST] Response = " + strResponse);
returnValue = true;
ResponseBody = strResponse;
}
}
catch (WebException ex)
{
//log.Error(Constants.GetEventID(50) + " - [POST] WebException = ", ex);
returnValue = false;
ResponseBody = ex.Message;
}
catch (Exception e)
{
//log.Error(Constants.GetEventID(51) + " - [POST] Exception = ", e);
returnValue = false;
ResponseBody = e.Message;
}
return returnValue;
}

public static bool GET(string uri, string username, string password, out string ResponseBody)
{
bool returnValue = false;
ResponseBody = string.Empty;
//log.Debug("[GET] URL = " + uri + "; username = " + username + "; password = " + password);

try
{
ServicePointManager.Expect100Continue = true;
ServicePointManager.ServerCertificateValidationCallback = new RemoteCertificateValidationCallback(delegate { return true; });
ServicePointManager.SecurityProtocol = SecurityProtocolType.Tls12;

HttpWebRequest request = (HttpWebRequest)WebRequest.Create(uri);
request.Method = "GET";
request.ContentType = @"application/json";
request.UserAgent = "Code Sample Web Client";
request.Credentials = new System.Net.NetworkCredential(username, password);

//request.AutomaticDecompression = DecompressionMethods.GZip | DecompressionMethods.Deflate;

using (HttpWebResponse response = (HttpWebResponse)request.GetResponse())
using (Stream stream = response.GetResponseStream())
using (StreamReader reader = new StreamReader(stream))
{
ResponseBody = reader.ReadToEnd();
}
returnValue = true;
}
catch (WebException ex)
{
//log.Error(Constants.GetEventID(52) + " - [GET] WebException = ", ex);
returnValue = false;
ResponseBody = ex.Message;
}
catch (Exception e)
{
//log.Error(Constants.GetEventID(53) + " - [GET] Exception = ", e);
returnValue = false;
ResponseBody = e.Message;
}
return returnValue;
}
}
Go to:   
Mobile view