簡體   English   中英

總是得到“套接字掛起'ECONNRESET'”

[英]Always getting “Socket Hang Up with 'ECONNRESET'”

嘗試命中時總是在回調方法的幫助下出錯,但總是出錯並試圖在NodeJS的POST HTTP方法中調用API,嘗試了所有解決方案,但一無所獲。

exports.createWallet = function(user_id, password, callback) {

var api_code = config.blockchain.api_code;
var user = user_id;
var pwd = password;

var result;

const post_data = JSON.stringify({
    'api_code': api_code,
    'password': pwd,
    'user_id': user
});

const options = {

    hostname: 'localhost',
    port: 8586,
    path: '/api/v2/create',
    method: 'POST',
    headers: {
        'Content-Type': 'application/x-www-form-urlencoded',
        'Content-Length': Buffer.byteLength(post_data)
    }
};

var request = https.request(options, function (response) {
});

request.on('error', function (error) {

    console.log(error);
});

// With http.request() one must always call request.end() to signify the end of the request - even if there is no data being written to the request body.
request.end();
};
 { Error: socket hang up at TLSSocket.onHangUp (_tls_wrap.js:1120:19) at Object.onceWrapper (events.js:293:19) at emitNone (events.js:91:20) at TLSSocket.emit (events.js:188:7) at endReadableNT (_stream_readable.js:975:12) at _combinedTickCallback (internal/process/next_tick.js:80:11) at process._tickCallback (internal/process/next_tick.js:104:9) code: 'ECONNR ESET' } 

在選項中,嘗試添加body: post_data

//只使用沒有https和在路徑中傳遞參數

var http = require("http");     
const options = {

    hostname: 'localhost',
    port: 8586,
    path: '/api/v2/create?api_code='+api_code+'&password='+pwd+'&user_id='+user,
    method: 'POST',
};

var request = http.request(options, function (response) {

}

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM