Click here to Skip to main content
16,018,057 members
Please Sign up or sign in to vote.
1.00/5 (2 votes)
See more:
Method for post api call:
string xml = "";
string Type = "", EventName = "", EventPath = "", UserName = "", Password = "";


Type = "POST";
EventName = "PREAPPROVALSUBMISSION";
EventPath = "https://www.devapi.anoudapps.com/api/medical/hospital-service/v3/pre-approval";
UserName = "nova_api";
Password = "nova_api123";


ServicePointManager.SecurityProtocol = (SecurityProtocolType)3072;

var encoding = System.Text.Encoding.GetEncoding("ISO-8859-1");
byte[] headerBytes = encoding.GetBytes(UserName + ":" + Password);
string headerValue = Convert.ToBase64String(headerBytes);


CookieContainer cookies = new CookieContainer();


HttpWebRequest webRequest = (HttpWebRequest)HttpWebRequest.Create(EventPath);
webRequest.Credentials = new NetworkCredential(UserName, Password);
webRequest.Method = Type;
webRequest.Headers.Add("company", "009");
webRequest.Headers.Add("Authorization", "Basic " + headerValue);
webRequest.ContentType = "multipart/form-data";
webRequest.CookieContainer = cookies;
webRequest.KeepAlive = true;


webRequest.Accept = "application/json";



//please use below data for post
var formdata = "{{\"policyNo\":\"P2209000174\"}, {\"memberId\":\"MEM21341411\"},
{\"category\":\"001\"},{\"illness\":\"001\"},{\"priority\":\"2\"},
{\"primaryDiagnosis\":\"R93.421\"},{\"medicalRecordNo\":\"0115731\"},{\"serviceType\":\"O\"},
{\"admissionType\":\"M\"},{\"visitDate\":\"19/02/2023\"},{\"doctorLicenseNo\":\"D8622\"}
{\"currency\":\"QAR\"},{\"mobileNo\":\"55849898\"},{\"illnessDetails\":\"follow up after
treatment of UTI\"},{\"treatmentsData\":\"
{\"treatType\":\"O\",\"treatCode\":\"51741\",\"quantity\":\"1\",\"treatDesc\":\"Urine flow
study\",\"estimatedAmount\":\"600.0000\",\"remarks\":\"\"},
{\"treatType\":\"O\",\"treatCode\":\"74183\",\"quantity\":\"1\",\"treatDesc\":\"MRI Abdomen
without and with contrast \",\"estimatedAmount\":\"3450.0000\",\"remarks\":\"\"},
{\"treatType\":\"O\",\"treatCode\":\"99242\",\"quantity\":\"1\",\"treatDesc\":\"Consultation -
Specialist (All)\",\"estimatedAmount\":\"300.0000\",\"remarks\":\"\"}\"}
{\"visitNo\":\"6461204\"},{\"medicalHistory\":\"Diabetes, dyslipidemia\"}}";


string inputJson = (new JavaScriptSerializer()).Serialize(formdata);
using (var streamWriter = new StreamWriter(webRequest.GetRequestStream()))
{
streamWriter.Write(inputJson);
streamWriter.Flush();
streamWriter.Close();

var webResponse = (HttpWebResponse)webRequest.GetResponse();




using (StreamReader streamReader = new StreamReader(webResponse.GetResponseStream()))
{
DataSet dsXml = new DataSet();
xml = streamReader.ReadLine();
StringReader sr = new StringReader(xml);
dsXml.ReadXml(sr);
if (dsXml.Tables[0].Rows.Count > 0)
{
if (common.myStr(dsXml.Tables[0].Rows[0]["messageType"]) != "S")
{
Alert.ShowAjaxMsg("Invalid Qatar Id", Page);
return;
}
}
dsXml.Dispose();
}

}

What I have tried:

Error throw: HTTP Validation: unparsable request content Details:No boundary define for multipart request
Posted
Updated 6-Mar-23 23:23pm

1 solution

We have no idea what data the remote service is expecting, so all we can do is guess.

You have a string variable called formdata which contains pre-serialized JSON. You then serialize that already-serialized variable again, and send that doubly-serialized data to the service.

It's highly likely that the service expects you to pass in the JSON, rather than a JSON-encoded string containing JSON.
C#
...

// Don't need to serialize again:
// string inputJson = (new JavaScriptSerializer()).Serialize(formdata);

using (var streamWriter = new StreamWriter(webRequest.GetRequestStream()))
{
    streamWriter.Write(formdata);
    streamWriter.Flush();
    streamWriter.Close();

    ...
 
Share this answer
 
Comments
jiten mutum 11-Mar-23 22:52pm    
Below are the credentials for posting. you can try in Postman.
Type = "POST";
EventName = "PREAPPROVALSUBMISSION";
EventPath = "https://www.devapi.anoudapps.com/api/medical/hospital-service/v3/pre-approval";
UserName = "nova_api";
Password = "nova_api123";

below are data you can use in postman:
var formdata = "{{\"policyNo\":\"P2209000174\"}, {\"memberId\":\"MEM21341411\"},
{\"category\":\"001\"},{\"illness\":\"001\"},{\"priority\":\"2\"},
{\"primaryDiagnosis\":\"R93.421\"},{\"medicalRecordNo\":\"0115731\"},{\"serviceType\":\"O\"},
{\"admissionType\":\"M\"},{\"visitDate\":\"19/02/2023\"},{\"doctorLicenseNo\":\"D8622\"}
{\"currency\":\"QAR\"},{\"mobileNo\":\"55849898\"},{\"illnessDetails\":\"follow up after
treatment of UTI\"},{\"treatmentsData\":\"
{\"treatType\":\"O\",\"treatCode\":\"51741\",\"quantity\":\"1\",\"treatDesc\":\"Urine flow
study\",\"estimatedAmount\":\"600.0000\",\"remarks\":\"\"},
{\"treatType\":\"O\",\"treatCode\":\"74183\",\"quantity\":\"1\",\"treatDesc\":\"MRI Abdomen
without and with contrast \",\"estimatedAmount\":\"3450.0000\",\"remarks\":\"\"},
{\"treatType\":\"O\",\"treatCode\":\"99242\",\"quantity\":\"1\",\"treatDesc\":\"Consultation -
Specialist (All)\",\"estimatedAmount\":\"300.0000\",\"remarks\":\"\"}\"}
{\"visitNo\":\"6461204\"},{\"medicalHistory\":\"Diabetes, dyslipidemia\"}}";

I have try without Serialize code you mention but still same error.
please try in postman and please share solution.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900