Answer the question
In order to leave comments, you need to log in
What is a POST request in C#?
There is a code on sharp, you need to rewrite it on nodejs. I don't understand what the request is about.
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';
Answer the question
In order to leave comments, you need to log in
What exactly do you not understand?
As for analogues, you can check with Fiddler or Wireshark.
Edge.js - allows you to execute pieces of C # code on a node. Conveniently. Try
1) a certificate is retrieved from the current user's certificate store by its serial number;
2) the client certificate received from the repository is attached to the request;
3) the content of poststr is written to the body of the POST request;
4) the request is sent and the program waits for a response from the server;
5) the response is encoded into the result string and output to the console;
I have no idea how to extract the certificate from the Windows storage in the node. The rest you will deal with yourself.
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question