Objective
Data encryption transmission, we often contact a number of ways one is ciphertext transmission, a clear text transmission ciphertext transmission, that is, the data encryption with the key, using the public key to decrypt the data, the transmission channel can be HTTPS or HTTP. PlainText transmission, provided that a secure transmission channel is established, where a certificate is used to protect the security of the channel, then the data is transmitted and the plaintext is used.
More professional can be later to share, but here I will introduce the clear text transmission, if it is to use Nodejs to establish a secure channel
Use two libraries, respectively Urllib and request, where the certificate only describes the use of a PFX file
Ways to Urllib libraries
Const Urllibrequest = (URL, method, data, PFX, pass) => {return to
new Promise (function (resolve, reject) {Let
op tions = {
Data:data,
Method:method,
pfx:pfx,
passphrase:pass,
rejectunauthorized:false
}
Urllib.request (URL, options, function (err, data, res) {
if (err) {return
reject (err);
}
Return Resolve (Data.tostring ());});}
The method of the request library
Const HttpRequest = (URL, method, data, PFX, pass) => {return to
new Promise (Resolve, reject) => {let
option s = {
Url:url,
Method:method,
form:data,
headers: {
' content-type ': ' application/ X-www-form-urlencoded '
},
agentoptions: {
pfx:pfx,
passphrase:pass,
rejectunauthorized: False
}
};
Request (options, function (err, HttpResponse, data) {
if (err) {return
reject (err);
}
Return resolve (data);})
}
Summarize
The above is the entire content of this article, I hope the content of this article for everyone's study or work can bring certain help, if you have questions you can message exchange.