public static DataSet PostData_PurpleAPITxnStatus1(Credentials crd, string Url, string MethodName, string JsonRequest, string SessionToken, string SoapAction = null, string ContentType = null, string EntireSopaAction = null, string Product = null, string Param1 = null, string Param2 = null, string Param3 = null, string Allow = null)
{
string Folderpath = ConfigurationManager.AppSettings["logpath"].ToString();
Folderpath = Folderpath + "\" + Product + "\" + System.DateTime.Now.ToString("dd-MM-yyy") + "\" + Param1 + "\";
if (!Directory.Exists(Folderpath))
Directory.CreateDirectory(Folderpath);
HttpWebRequest webrequest = null;
HttpWebResponse resp = null;
var requestInterceptor = new SymexInspector();
xmlSymexFileWriter xmlwrite = new xmlSymexFileWriter();
Random RandomNumber = new Random();
//var requestDataBytes = "";
DataSet ds = new DataSet();
string apiUrl = "https://api.test.purplme.com/remittances/131/";
string ResponseData = string.Empty;
string resulXmlFromWebService = string.Empty;
string AuthHeader = SessionToken;
try
{
ServicePointManager.Expect100Continue = true;
// ServicePointManager.SecurityProtocol = SecurityProtocolType.Tls | SecurityProtocolType.Ssl3 | (SecurityProtocolType)3072 | (SecurityProtocolType)768 | SecurityProtocolType.Tls12;
ServicePointManager.SecurityProtocol = SecurityProtocolType.Tls11 | SecurityProtocolType.Ssl3 | SecurityProtocolType.Tls12;
ServicePointManager.ServerCertificateValidationCallback = delegate { return true; };
webrequest = (HttpWebRequest)WebRequest.Create(apiUrl);
webrequest.Method = "GET";
webrequest.Headers["Authorization"] = "Bearer " + AuthHeader;
webrequest.ContentType = "application/json";
resp = (HttpWebResponse)webrequest.GetResponse();
using (StreamReader reader = new StreamReader(resp.GetResponseStream()))
{
ResponseData = reader.ReadToEnd();
}
resp = (HttpWebResponse)webrequest.GetResponse();
using (StreamReader reader = new StreamReader(resp.GetResponseStream()))
{
ResponseData = reader.ReadToEnd();
}
}
#region ErroCatch
catch (WebException webex)
{
string Response = "";
WebResponse response = webex.Response;
if (response == null)
{
string ResponseXml = ("<Response><ErroCode>-99</ErroCode><ErroDesc>" + webex.Message.ToString() + "</ErroDesc></Response>");
StringReader srError = new StringReader(ResponseXml);
ds.ReadXml(srError);
}
else
{
using (response = webex.Response)
{
HttpWebResponse httpResponse = (HttpWebResponse)response;
using (Stream data = response.GetResponseStream())
using (var reader = new StreamReader(data))
{
Response = reader.ReadToEnd();
}
}
string Resp = ReadDataFromJsontoXml(Response);
StringReader srs = new StringReader(Resp);
ds.ReadXml(srs);
}
}
catch (XmlSchemaInferenceException XmlException)
{
xmlwrite.WriteXml(JsonRequest, XmlException.Message.ToString(), Folderpath, string.Empty, string.Empty, Param1.Substring(0, 3) + System.DateTime.Now.ToString("ddMMMyyyyhhmmss") + "_" + ((Param3.Length == 0) || (Param3 == null) ? "0" : Param3.ToString()));
StringReader sr = new StringReader(resulXmlFromWebService);
ds.ReadXml(sr, XmlReadMode.ReadSchema);
}
catch (Exception ex)
{
xmlwrite.WriteXml(JsonRequest, ex.Message.ToString() + " " + ex.StackTrace.ToString(), Folderpath, string.Empty, string.Empty, Param1.Substring(0, 3) + System.DateTime.Now.ToString("ddMMMyyyyhhmmss") + "_" + ((Param3.Length == 0) || (Param3 == null) ? "0" : Param3.ToString()));
string ResponseXml = ("<Response><ErroCode>-99</ErroCode><ErroDesc>Exception while Posting the data...</ErroDesc></Response>");
StringReader srError = new StringReader(ResponseXml);
ds.ReadXml(srError);
}
#endregion
return ds;
}
The above code returns 404 error from API but in postman its working fine
Sreeja is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.