Mario SAg

Mario SAg

  • NA
  • 1
  • 1k

i! I got a problem make the curl command equivalent to my C#

May 23 2016 5:31 AM
  1. $ curl  
  2. -X POST  
  3. -H "Authorization: Bearer YOUR_ACCESS_TOKEN"  
  4. -F "recipients[0][name]=John"  
  5. -F "recipients[0][email][email protected]"  
  6. -F "files[0]=@/path/to/the/pdf/document.pdf"  
  7. https://api.sandbox.signaturit.com/v3/signatures.json  

i made this code in c#
  1. using System;  
  2. using System.IO;  
  3. using System.Net;  
  4. using System.Text;  
  5. using System.Web;  
  6.   
  7. public class Program  
  8. {  
  9.     public static void Main()  
  10.     {  
  11.         string response = SendSignatureRequest(  
  12.             "ZDM4NzU1YTVmNmFhNGMwMGQ3MTdiOTBhNmNiZDQzOTlkYjg4OTk0MTg5MGM3OGFlZjk1OWM1ZDg1NTQxYzBjYQ",  
  13.             "Mario",  
  14.             "[email protected]",  
  15.             //"http://www.analysis.im/uploads/seminar/pdf-sample.pdf"  
  16.             "@c://Mariete.pdf"  
  17.         );  
  18.         Console.WriteLine(response);  
  19.     }  
  20.   
  21.     public static string SendSignatureRequest(string apiKey, string name, string email, string file)  
  22.     {  
  23.         HttpWebRequest request = (HttpWebRequest)WebRequest.Create("https://api.sandbox.signaturit.com/v3/signatures.json");  
  24.         request.Method = "POST";  
  25.           
  26.         string authorization = apiKey;  
  27.         request.Headers.Add("Authorization""Bearer " + authorization);  
  28.           
  29.         
  30.   
  31.         var postData = "recipients[0][name]=" + name;  
  32.             postData += "&recipients[0][email]=" + email;  
  33.             postData += "&files[0]=" + file;  
  34.               
  35.         
  36.         var data = Encoding.ASCII.GetBytes(postData);  
  37.           
  38.         request.ContentType = "application/json";  
  39.         request.ContentLength = data.Length;  
  40.           
  41.         using (var stream = request.GetRequestStream())  
  42.         {  
  43.             stream.Write(data, 0, data.Length);  
  44.               
  45.         }  
  46.   
  47.         HttpWebResponse response = (HttpWebResponse)request.GetResponse();  
  48.         return new StreamReader(response.GetResponseStream()).ReadToEnd();  
  49.     }  
  50. }