Advertisement
Guest User

Untitled

a guest
Jan 20th, 2016
734
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 2.70 KB | None | 0 0
  1.         static void Main(string[] args)
  2.         {
  3.             var Log = new LoggerConfiguration()
  4.                         .WriteTo.ColoredConsole()
  5.                         .WriteTo.RollingFile(@"Log-{Date}.txt")
  6.                         .CreateLogger();
  7.  
  8.             string DataToPost = "{ \"payeePaymentReference\": \"0123456789\", " +
  9.                                     "\"callbackUrl\": \"https://admin.dibspayment.com/\", " +
  10.                                      "\"payerAlias\": \"46731596605\", " +
  11.                                      "\"payeeAlias\": \"1231181189\", " +
  12.                                      "\"amount\": \"100\", " +
  13.                                      "\"currency\": \"SEK\", " +
  14.                                      "\"message\": \"Order xx\" }";
  15.  
  16.             string URL = "https://mss.swicpc.bankgirot.se/swish-cpcapi/api/v1/paymentrequests/";
  17.  
  18.             //ServicePointManager.Expect100Continue = true;
  19.  
  20.             ServicePointManager.SecurityProtocol = SecurityProtocolType.Tls11;
  21.  
  22.             //Cert Challenge URL
  23.             Uri requestURI = new Uri(URL);
  24.  
  25.             //Create the Request Object
  26.             HttpWebRequest req = (HttpWebRequest)WebRequest.Create(requestURI);
  27.  
  28.             //Set the Request Object parameters
  29.             req.ContentType = "application/json; charset=UTF-8";
  30.             req.Method = "POST";
  31.             req.ProtocolVersion = HttpVersion.Version10;
  32.            
  33.             X509Certificate cert = new X509Certificate2("Swish Merchant Test Certificate 1231181189.p12", "swish", X509KeyStorageFlags.Exportable | X509KeyStorageFlags.PersistKeySet);
  34.  
  35.             req.ClientCertificates.Add(cert);
  36.  
  37.             try
  38.             {
  39.                 WebResponse response = req.GetResponse();
  40.  
  41.                 String result = "";
  42.  
  43.                 using (StreamReader rdr = new StreamReader(response.GetResponseStream()))
  44.                 {
  45.                     result = rdr.ReadToEnd();
  46.                 }
  47.  
  48.                 Log.Debug("Result: " + result);
  49.             }
  50.             catch (WebException e)
  51.             {
  52.                 using (WebResponse response = e.Response)
  53.                 {
  54.                     HttpWebResponse httpResponse = (HttpWebResponse)response;
  55.                    
  56.                     Log.Information("Error code: {0}", httpResponse.StatusCode);
  57.  
  58.                     using (Stream data = response.GetResponseStream())
  59.                     {
  60.                         string text = new StreamReader(data).ReadToEnd();
  61.                         Log.Information(text);
  62.                     }
  63.                 }
  64.             }
  65.             Console.WriteLine(">>> Press enter to exit <<<");
  66.             Console.ReadLine();
  67.         }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement