Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- static void Main(string[] args)
- {
- var Log = new LoggerConfiguration()
- .WriteTo.ColoredConsole()
- .WriteTo.RollingFile(@"Log-{Date}.txt")
- .CreateLogger();
- string DataToPost = "{ \"payeePaymentReference\": \"0123456789\", " +
- "\"callbackUrl\": \"https://admin.dibspayment.com/\", " +
- "\"payerAlias\": \"46731596605\", " +
- "\"payeeAlias\": \"1231181189\", " +
- "\"amount\": \"100\", " +
- "\"currency\": \"SEK\", " +
- "\"message\": \"Order xx\" }";
- string URL = "https://mss.swicpc.bankgirot.se/swish-cpcapi/api/v1/paymentrequests/";
- //ServicePointManager.Expect100Continue = true;
- ServicePointManager.SecurityProtocol = SecurityProtocolType.Tls11;
- //Cert Challenge URL
- Uri requestURI = new Uri(URL);
- //Create the Request Object
- HttpWebRequest req = (HttpWebRequest)WebRequest.Create(requestURI);
- //Set the Request Object parameters
- req.ContentType = "application/json; charset=UTF-8";
- req.Method = "POST";
- req.ProtocolVersion = HttpVersion.Version10;
- X509Certificate cert = new X509Certificate2("Swish Merchant Test Certificate 1231181189.p12", "swish", X509KeyStorageFlags.Exportable | X509KeyStorageFlags.PersistKeySet);
- req.ClientCertificates.Add(cert);
- try
- {
- WebResponse response = req.GetResponse();
- String result = "";
- using (StreamReader rdr = new StreamReader(response.GetResponseStream()))
- {
- result = rdr.ReadToEnd();
- }
- Log.Debug("Result: " + result);
- }
- catch (WebException e)
- {
- using (WebResponse response = e.Response)
- {
- HttpWebResponse httpResponse = (HttpWebResponse)response;
- Log.Information("Error code: {0}", httpResponse.StatusCode);
- using (Stream data = response.GetResponseStream())
- {
- string text = new StreamReader(data).ReadToEnd();
- Log.Information(text);
- }
- }
- }
- Console.WriteLine(">>> Press enter to exit <<<");
- Console.ReadLine();
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement