Есть код на шарпе, нужно переписать его на nodejs. Не понимаю о чем речь в запросе.
using System;
using System.Text;
using System.Net;
using System.Security.Cryptography.X509Certificates;
using System.IO;
using System.Web;
namespace DemoUseClientCertificate
{
class Program
{
static void Main(string[] args)
{
string url = "https://apitest.startssl.com";
string jsonstr = "{\"tokenID\" : \"tk_e5e1df6d15bb48728e3f136864c141e5\",\"actionType\" : \"ApplyWebControl \",\"hostname\" : \"a.startssl.com\"}";
string poststr = "RequestData=" + HttpUtility.UrlEncode(jsonstr);
byte[] data = Encoding.Default.GetBytes(poststr);
string ClientCert_SerialNumber = "your client cert serial number";
HttpWebRequest myRequest = (HttpWebRequest)WebRequest.Create(url);
try
{
X509Store store = new X509Store(StoreName.My, StoreLocation.CurrentUser);
store.Open(OpenFlags.ReadOnly);
X509Certificate2Collection certs = store.Certificates.Find(X509FindType.FindBySerialNumber, ClientCert_SerialNumber, false);
myRequest.Method = "POST";
myRequest.ContentType = "application/x-www-form-urlencoded";
myRequest.ContentLength = data.Length;
myRequest.ClientCertificates.Add(certs[0]);
Stream newStream = myRequest.GetRequestStream();
newStream.Write(data, 0, data.Length);
newStream.Close();
var response = (HttpWebResponse)myRequest.GetResponse();
using (var reader = new StreamReader(response.GetResponseStream(), Encoding.GetEncoding("UTF-8")))
{
string result = reader.ReadToEnd();
reader.Close();
response.Close();
Console.WriteLine(result);
}
}
catch (Exception ex)
{
}
}
}
}
Пока написал это. Помогите набросать аналог этого реквеста на ноде.
var querystring = require('querystring');
var url = 'https://apitest.startssl.com';
var jsonstr = { "tokenID" : "tk_50ab059220e545f881652eac98772c21",
"actionType" : "ApplyWebControl",
"hostname" : "a.startssl.com"};
var poststr = 'RequestData=' + querystring.stringify(jsonstr);
var bytes_data = [];
for (var i = 0; i < poststr.length; ++i) {
bytes_data.push(poststr.charCodeAt(i));
}
var ClientCert_SerialNumber = '666E1337C65075631C46ECFF79AFA301';