2017-07-06 5 views
0

Ich habe diesen cUrl Befehl für PHP:Transform cUrl PHP in cUrl C# .Net

curl --user AUTH_KEY:AUTH_SECRET -XPOST https://api.smshosting.it/rest/api/sms/send \ 
-d "from=mrossi" \ 
-d "to=393480000000" \ 
-d "text=Test Sms" 

POST type = "application/x-www-form-urlencoded"

Info unter: https://www.smshosting.it/it/docs/sms-rest-api/invio

aber jetzt muss ich es in C# .Net 4.5 verwenden.

Ich habe keine Ahnung, wo allerdings zu beginnen, ich glaube nicht, dass es kompliziert, aber ich habe nie die Locke in C#

Antwort

0
string url = "https://api.smshosting.it/rest/api/sms/send"; 
      WebRequest request = WebRequest.Create(url); 
      request.ContentType = "application/x-www-form-urlencoded"; 
      request.Method = "POST"; 
      string authInfo = "XXXXXXXXXXXX:XXXXXXXXXXXX"; 
      request.Headers["Authorization"] = "Basic " + Convert.ToBase64String(Encoding.ASCII.GetBytes(authInfo)); 
      byte[] buffer = Encoding.GetEncoding("UTF-8").GetBytes("from=XXXX&to=XXXXXX&text=XXXXX"); 
      Stream reqstr = request.GetRequestStream(); 
      reqstr.Write(buffer, 0, buffer.Length); 
      reqstr.Close();