Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public static bool CertValidation(object sender, X509Certificate certificate, X509Chain chain, SslPolicyErrors sslpolicyErrors)
- {
- bool result = true;
- // TODO: implement
- return result;
- }
- public static string HttpPostJSonString(string url, string postData)//user_key untuk ws vclaim 2
- {
- string responseFromServer = "";
- try
- {
- System.Net.ServicePointManager.ServerCertificateValidationCallback = new RemoteCertificateValidationCallback(CertValidation);
- HttpWebRequest request = WebRequest.Create(new Uri(url)) as HttpWebRequest;
- // Set the Method property of the request to POST.
- request.Method = "POST";
- //req.Timeout = 10000;// 10 seconds // belum ada issue jangan dipasang dulu
- //req.Headers.Add("Accept", "application/json");
- request.Headers.Add("X-cons-id", xConsId);
- request.Headers.Add("X-timestamp", xTimeStamp);
- request.Headers.Add("X-signature", xSignature);
- // Create POST data and convert it to a byte array.
- //string postData = "This is a test that posts this string to a Web server.";
- byte[] byteArray = Encoding.UTF8.GetBytes(postData);
- // Set the ContentType property of the WebRequest.
- request.ContentType = "application/x-www-form-urlencoded";//application/xml;charset=UTF-8
- // Set the ContentLength property of the WebRequest.
- req.ContentLength = byteArray.Length;
- // Get the request stream.
- Stream dataStream = req.GetRequestStream();
- // Write the data to the request stream.
- dataStream.Write(byteArray, 0, byteArray.Length);
- // Close the Stream object.
- dataStream.Close();
- // Get the response.
- WebResponse response = req.GetResponse();
- // Display the status.
- // Console.WriteLine(((HttpWebResponse)response).StatusDescription);
- // Get the stream containing content returned by the server.
- dataStream = response.GetResponseStream();
- // Open the stream using a StreamReader for easy access.
- StreamReader reader = new StreamReader(dataStream);
- // Read the content.
- responseFromServer = reader.ReadToEnd();
- // Display the content.
- Console.WriteLine(responseFromServer);
- // Clean up the streams.
- reader.Close();
- dataStream.Close();
- response.Close();
- } catch (Exception ex) {
- responseFromServer = ex.Message;
- }
- return responseFromServer;
- }
- string endPoint = "";
- string postData = JsonConvert.SerializeObject(YourModel);
- string responseString = BPJSBridge.HttpPostJSonString($"{endPoint}",postData);
- ResponseModel responseModel = JsonConvert.DeserializeObject<ResponseModel>(responseString);
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement