Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- var util = require('util');
- var http = require('http');
- var fs = require('fs');
- var querystring = require('querystring');
- var winston = require('winston');
- var config = require('../config/config');
- const pHost = config.server_communications.dserver_ip;
- const pPort = config.server_communications.dserver_port;
- function addSpaces(value) {
- return value + new Array(16-value.length + 1).join(' ');
- }
- module.exports = {
- /* unused function */
- getControllerHTTP: function (pCommandJSON, pHost, pPort, pUsername, pPassword, callback) {
- //var username = "s1";
- //var password = "s1";
- var auth = "Basic " + new Buffer(pUsername + ":" + pPassword).toString("base64");
- //var post_data = querystring.stringify({
- // pCommandName : ''
- //});
- var post_data = querystring.stringify(pCommandJSON);
- winston.info("HTTP helper getControllerHTTP HOST: " + pHost);
- var post_options = {
- host: pHost,
- port: pPort,
- path: '/',
- method: 'POST',
- headers: {
- 'Content-Type': 'application/x-www-form-urlencoded',
- 'Content-Length': Buffer.byteLength(post_data),
- 'Authorization': auth,
- 'Cache-Control': 'no-cache'
- }
- };
- console.log("auth: " + auth);
- var post_req = http.request(post_options, function (res1) {
- //res.setEncoding('utf8');
- res1.on('data', function (chunk) {
- //console.log('Response: ' + util.inspect(chunk.toString()));
- var chunkStr = chunk.toString();
- var ind1 = chunkStr.indexOf("<h1>") + 4;
- var ind2 = chunkStr.indexOf("</h1>");
- var h1Resp = chunkStr;//.substring(ind1, ind2);
- callback(null, {
- h1_resp: h1Resp
- });
- });
- });
- post_req.on('error', function (err) {
- console.log("error on requesting devices state");
- callback(null, {error: err});
- });
- post_req.write(post_data);
- post_req.end();
- },
- sendControllerCommandHTTP: function (pCommandJSON, deviceSerialNumber, callback) {
- var h1Resp = {fromServer: 'firmware:2.3.76WDT\r\nreleased:2016/08/03\r\npartnumb:0123456789ABCDEF\r\nserialnu:0000000000000100\r\n'};
- return callback(null, {h1_resp: h1Resp});
- var post_data = querystring.stringify({serial_number: addSpaces(deviceSerialNumber), command:pCommandJSON});
- var post_options = {
- host: pHost,
- port: pPort,
- path: '/',
- method: 'POST',
- headers: {
- 'Content-Type': 'application/x-www-form-urlencoded',
- 'Content-Length': Buffer.byteLength(post_data),
- 'Cache-Control': 'no-cache'
- }
- };
- /*callback = function(response) {
- var str = ''
- response.on('data', function (chunk) {
- str += chunk;
- });
- response.on('end', function () {
- console.log(str);
- });
- }
- var req = http.request(options, callback);
- req.write(post_data);
- req.end();*/
- var post_req = http.request(post_options, function (res1) {
- //res.setEncoding('utf8');
- res1.on('data', function (chunk) {
- //console.log('Response: ' + util.inspect(chunk.toString()));
- var chunkStr = chunk.toString();
- var ind1 = chunkStr.indexOf("<h1>") + 4;
- var ind2 = chunkStr.indexOf("</h1>");
- var h1Resp = chunkStr;//.substring(ind1, ind2);
- callback(null, {h1_resp: h1Resp});
- });
- });
- post_req.on('error', function (err) {
- console.log("error on requesting devices state");
- callback(null, {error: err});
- });
- post_req.write(post_data);
- post_req.end();
- },
- sendControllerCommandKeyHTTP: function (keyValue, deviceSerialNumber, callback) {
- var h1Resp = fs.readFileSync("PBFACU.CFG", "utf8");
- console.log("h1Resp body: " + h1Resp);
- return callback(null, {h1_resp: h1Resp});
- var post_data = querystring.stringify({serial_number:deviceSerialNumber, key_value:keyValue});
- var post_options = {
- host: pHost,
- port: pPort,
- path: '/',
- method: 'POST',
- headers: {
- 'Content-Type': 'application/x-www-form-urlencoded',
- 'Content-Length': Buffer.byteLength(post_data),
- 'Cache-Control': 'no-cache'
- }
- };
- /*callback = function(response) {
- var str = ''
- response.on('data', function (chunk) {
- str += chunk;
- });
- response.on('end', function () {
- console.log(str);
- });
- }
- var req = http.request(options, callback);
- req.write(post_data);
- req.end();*/
- var post_req = http.request(post_options, function (res1) {
- //res.setEncoding('utf8');
- res1.on('data', function (chunk) {
- //console.log('Response: ' + util.inspect(chunk.toString()));
- var chunkStr = chunk.toString();
- var ind1 = chunkStr.indexOf("<h1>") + 4;
- var ind2 = chunkStr.indexOf("</h1>");
- var h1Resp = chunkStr;//.substring(ind1, ind2);
- callback(null, {h1_resp: h1Resp});
- });
- });
- post_req.on('error', function (err) {
- console.log("error on requesting devices state");
- callback(null, {error: err});
- });
- post_req.write(post_data);
- post_req.end();
- },
- getControllerSetupCommandHTTP: function (deviceSerialNumber, callback) {
- /* var h1Resp = fs.readFileSync("PBFACU.CFG", "utf8");
- console.log("h1Resp body: " + h1Resp);
- return callback(null, {h1_resp: h1Resp}); */
- var configFileName = "PBFACU.CFG";
- var pCommand = "GET_CONFIG";
- var post_data = querystring.stringify({serial_number: addSpaces(deviceSerialNumber), command:pCommand, file_name:configFileName});
- var post_options = {
- host: pHost,
- port: pPort,
- path: '/',
- method: 'POST',
- headers: {
- 'Content-Type': 'application/x-www-form-urlencoded',
- 'Content-Length': Buffer.byteLength(post_data),
- 'Cache-Control': 'no-cache'
- }
- };
- var post_req = http.request(post_options, function (res1) {
- res1.on('data', function (chunk) {
- var chunkStr = chunk.toString();
- var ind1 = chunkStr.indexOf("<h1>") + 4;
- var ind2 = chunkStr.indexOf("</h1>");
- var h1Resp = chunkStr;
- callback(null, {h1_resp: h1Resp});
- });
- });
- post_req.on('error', function (err) {
- console.log("error on requesting devices state");
- callback(null, {error: err});
- });
- post_req.write(post_data);
- post_req.end();
- },
- getControllerLogCommandHTTP: function (deviceSerialNumber, callback) {
- var pCommand = "GET_LOG";
- var post_data = querystring.stringify({serial_number: addSpaces(deviceSerialNumber), command:pCommand});
- var post_options = {
- host: pHost,
- port: pPort,
- path: '/',
- method: 'POST',
- headers: {
- 'Content-Type': 'application/x-www-form-urlencoded',
- 'Content-Length': Buffer.byteLength(post_data),
- 'Cache-Control': 'no-cache'
- }
- };
- var post_req = http.request(post_options, function (res1) {
- var buffArray = [];
- res1.on('data', function (chunk) {
- buffArray.push(chunk.toString());
- });
- res1.on('end', function (res) {
- callback(null, {h1_resp: buffArray.join()});
- });
- });
- post_req.on('error', function (err) {
- console.log("error on requesting devices state");
- callback(null, {error: err});
- });
- post_req.write(post_data);
- post_req.end();
- //var h1Resp = "2016/04/22-13:38:19 Log created\r\n2016/04/22-13:38:19 Powered up\r\n2016/04/22-13:38:19 Last shutdown time 1970/01/01-00:00:00\r\n2016/04/22-13:38:29 ************************************************************";
- //callback(null, {h1_resp: h1Resp});
- },
- getControllerFileCommandHTTP: function (configFileName, deviceSerialNumber, callback) {
- var pCommand = "GET_CONFIG";
- var post_data = querystring.stringify({serial_number: addSpaces(deviceSerialNumber), command:pCommand, file_name:configFileName});
- var post_options = {
- host: pHost,
- port: pPort,
- path: '/',
- method: 'POST',
- headers: {
- 'Content-Type': 'application/x-www-form-urlencoded',
- 'Content-Length': Buffer.byteLength(post_data),
- 'Cache-Control': 'no-cache'
- }
- };
- var post_req = http.request(post_options, function (res1) {
- var buffArray = new Buffer('');
- res1.on('data', function (chunk) {
- buffArray = Buffer.concat([buffArray,chunk]);
- });
- res1.on('end', function (res) {
- callback(null, {h1_resp: buffArray});
- });
- });
- post_req.on('error', function (err) {
- console.log("error on requesting devices state");
- callback(null, {error: err});
- });
- post_req.write(post_data);
- post_req.end();
- },
- uploadControllerHTTP: function (pFileName, pMimeType, pOriginalFileName, pDeviceSerialNumber, callback) {
- //var fs = require("fs");
- var data = null; // надо правильно обрабаотывать ошибку если файл не найден!
- try {
- data = fs.readFileSync("upload/" + pFileName);
- } catch (e) {
- console.error("File not found");
- return callback(e, {h1_resp: ''});
- }
- var client;
- var request;
- /* As per http://www.w3.org/Protocols/rfc1341/7_2_Multipart.html */
- var crlf = "\r\n",
- boundary = '--------120315120542026', // Boundary: "--" + up to 70 ASCII chars + "\r\n"
- delimiter = "--" + boundary,
- preamble = "", // ignored. a good place for non-standard mime info
- epilogue = ""; // ignored. a good place to place a checksum, etc
- //application/octet-stream
- var qOriginalFileName = pOriginalFileName+ " " + addSpaces(pDeviceSerialNumber);
- console.log("uploadHTTP pOriginalFileName: " + qOriginalFileName);
- var headers = [
- 'Content-Disposition: form-data; name="userfile"; filename="' + qOriginalFileName + '"' + crlf,
- //'Content-Type: application/octet-stream' + crlf,
- //'Content-Type: ' + pMimeType + crlf
- 'Content-Type: application/octet-stream' + crlf
- ],
- //bodyPart = headers.join('') + crlf + data.toString(),
- //encapsulation = delimiter + crlf + bodyPart,
- closeDelimiter = delimiter + "--",
- multipartBody; // = preamble + encapsulation + closeDelimiter + epilogue + crlf /* node doesn't add this */;
- multipartBody = Buffer.concat([
- new Buffer(preamble + delimiter + crlf + headers.join('') + crlf),
- data,
- new Buffer(crlf + closeDelimiter + epilogue + crlf)]
- );
- //console.log("multipartBody: " + multipartBody);
- console.log("multipartBody length: " + multipartBody.length);
- //client = http.request(pPort, pHost);
- /* headers copied from a browser request logged in wireshark */
- //'POST', '/cgi-bin/upload',
- var post_options = {
- host: pHost,
- port: pPort,
- path: '/cgi-bin/upload',
- method: 'POST',
- headers: {
- 'Accept': 'text/html, */*',
- 'Accept-Encoding': 'identity',
- 'User-Agent': 'Mozilla/3.0 (compatible; Indy Library)',//'Node.JS',
- 'Connection': 'keep-alive',
- 'Content-Type': 'multipart/form-data; boundary=' + boundary,
- 'Content-Length': multipartBody.length
- }
- };
- console.log('post_options:'+ JSON.stringify(post_options));
- var request1 = http.request(post_options, function (res) {
- //console.log('STATUS: ${res.statusCode}');
- //console.log('HEADERS: ${JSON.stringify(res.headers)}');
- res.setEncoding('utf8');
- var h1Resp = "H1 response not found";
- res.on('data', function (chunk) {
- var chunkStr = chunk.toString();
- //console.log("onData chunkStr: " + chunkStr);
- var ind1 = chunkStr.indexOf("<h1>");
- var ind2 = chunkStr.indexOf("</h1>");
- if (ind1 != -1) {
- h1Resp = chunkStr.substring(ind1 + 4, ind2);
- }
- return callback(null, {
- h1_resp: "File has been uploaded"
- });
- });
- }
- );
- request1.on('error', function (err) {
- console.log("Error event occured. Err: " + util.inspect(err));
- callback(err, {h1_resp: ''});
- });
- request1.write(multipartBody);
- request1.end();
- },
- getControllersStatusesListHTTP: function (pHost, pPort, callback) {
- var pCommand = "GET_CONTROLLERS_STATUSES";
- var post_data = querystring.stringify({command:pCommand});
- var post_options = {
- host: pHost,
- port: pPort,
- path: '/',
- method: 'POST',
- headers: {
- 'Content-Type': 'application/x-www-form-urlencoded',
- 'Content-Length': Buffer.byteLength(post_data),
- 'Cache-Control': 'no-cache'
- }
- };
- var post_req = http.request(post_options, function (res1) {
- var buffArray = [];
- res1.on('data', function (chunk) {
- buffArray.push(chunk.toString());
- });
- res1.on('end', function (res) {
- callback(null, {h1_resp: buffArray.join()});
- });
- });
- post_req.on('socket', function (socket) {
- socket.setTimeout(5000);
- socket.on('timeout', function() {
- post_req.abort();
- callback(null, {error: "err"});
- });
- });
- post_req.on('error', function (err) {
- console.log("error on requesting devices state");
- callback(null, {error: err});
- });
- post_req.write(post_data);
- post_req.end();
- //var h1Resp = "2016/04/22-13:38:19 Log created\r\n2016/04/22-13:38:19 Powered up\r\n2016/04/22-13:38:19 Last shutdown time 1970/01/01-00:00:00\r\n2016/04/22-13:38:29 ************************************************************";
- //callback(null, {h1_resp: h1Resp});
- },
- uploadControllerConfigFileHTTP: function (pFileName, pMimeType, pDeviceSerialNumber, pData, callback) {
- return callback(null, {
- h1_resp: "File has been uploaded"
- });
- //var fs = require("fs");
- var data = pData; // надо правильно обрабаотывать ошибку если файл не найден!
- /*try {
- data = fs.readFileSync("upload/" + pFileName);
- } catch (e) {
- console.error("File not found");
- return callback(e, {h1_resp: ''});
- }*/
- var client;
- var request;
- //var saveConfigCommand = "SAVE_CONFIG\r\n";
- /* As per http://www.w3.org/Protocols/rfc1341/7_2_Multipart.html */
- var crlf = "\r\n",
- boundary = '--------120315120542026', // Boundary: "--" + up to 70 ASCII chars + "\r\n"
- delimiter = "--" + boundary,
- preamble = "", // ignored. a good place for non-standard mime info
- epilogue = ""; // ignored. a good place to place a checksum, etc
- //application/octet-stream
- var qOriginalFileName = pFileName+ " " + addSpaces(pDeviceSerialNumber);
- console.log("uploadHTTP pOriginalFileName: " + qOriginalFileName);
- var headers = [
- 'Content-Disposition: form-data; name="userfile"; filename="' + qOriginalFileName + '"' + crlf,
- //'Content-Type: application/octet-stream' + crlf,
- //'Content-Type: ' + pMimeType + crlf
- 'Content-Type: application/octet-stream' + crlf
- ],
- //bodyPart = headers.join('') + crlf + data.toString(),
- //encapsulation = delimiter + crlf + bodyPart,
- closeDelimiter = delimiter + "--",
- multipartBody; // = preamble + encapsulation + closeDelimiter + epilogue + crlf /* node doesn't add this */;
- multipartBody = Buffer.concat([
- new Buffer(preamble + delimiter + crlf + headers.join('') + crlf),
- new Buffer(data),
- //new Buffer(saveConfigCommand),
- new Buffer(crlf + closeDelimiter + epilogue + crlf)]
- );
- //console.log("multipartBody: " + multipartBody);
- console.log("multipartBody length: " + multipartBody.length);
- //client = http.request(pPort, pHost);
- /* headers copied from a browser request logged in wireshark */
- //'POST', '/cgi-bin/upload',
- var post_options = {
- host: pHost,
- port: pPort,
- path: '/cgi-bin/upload',
- method: 'POST',
- headers: {
- 'Accept': 'text/html, */*',
- 'Accept-Encoding': 'identity',
- 'User-Agent': 'Mozilla/3.0 (compatible; Indy Library)',//'Node.JS',
- 'Connection': 'keep-alive',
- 'Content-Type': 'multipart/form-data; boundary=' + boundary,
- 'Content-Length': multipartBody.length
- }
- };
- console.log('post_options:'+ JSON.stringify(post_options));
- var request1 = http.request(post_options, function (res) {
- //console.log('STATUS: ${res.statusCode}');
- //console.log('HEADERS: ${JSON.stringify(res.headers)}');
- res.setEncoding('utf8');
- var h1Resp = "H1 response not found";
- res.on('data', function (chunk) {
- var chunkStr = chunk.toString();
- //console.log("onData chunkStr: " + chunkStr);
- var ind1 = chunkStr.indexOf("<h1>");
- var ind2 = chunkStr.indexOf("</h1>");
- if (ind1 != -1) {
- h1Resp = chunkStr.substring(ind1 + 4, ind2);
- }
- return callback(null, {
- h1_resp: "File has been uploaded"
- });
- });
- }
- );
- request1.on('error', function (err) {
- console.log("Error event occured. Err: " + util.inspect(err));
- callback(err, {h1_resp: ''});
- });
- request1.write(multipartBody);
- request1.end();
- },
- uploadControllerFileHTTP: function (pFileName, pMimeType, pDeviceSerialNumber, pData, callback) {
- var data = pData; // надо правильно обрабаотывать ошибку если файл не найден!
- var client;
- var request;
- //var saveConfigCommand = "SAVE_CONFIG\r\n";
- /* As per http://www.w3.org/Protocols/rfc1341/7_2_Multipart.html */
- var crlf = "\r\n",
- boundary = '--------120315120542026', // Boundary: "--" + up to 70 ASCII chars + "\r\n"
- delimiter = "--" + boundary,
- preamble = "", // ignored. a good place for non-standard mime info
- epilogue = ""; // ignored. a good place to place a checksum, etc
- //application/octet-stream
- var qOriginalFileName = pFileName+ " " + addSpaces(pDeviceSerialNumber);
- console.log("uploadHTTP pOriginalFileName: " + qOriginalFileName);
- var headers = [
- 'Content-Disposition: form-data; name="userfile"; filename="' + qOriginalFileName + '"' + crlf,
- //'Content-Type: application/octet-stream' + crlf,
- //'Content-Type: ' + pMimeType + crlf
- 'Content-Type: application/octet-stream' + crlf
- ],
- //bodyPart = headers.join('') + crlf + data.toString(),
- //encapsulation = delimiter + crlf + bodyPart,
- closeDelimiter = delimiter + "--",
- multipartBody = ""; // = preamble + encapsulation + closeDelimiter + epilogue + crlf /* node doesn't add this */;
- try {
- multipartBody = Buffer.concat([
- new Buffer(preamble + delimiter + crlf + headers.join('') + crlf),
- new Buffer(data),
- //new Buffer(saveConfigCommand),
- new Buffer(crlf + closeDelimiter + epilogue + crlf)]
- );
- } catch (e) {
- winston.error("Error on creating multipart body: " + e);
- }
- //console.log("multipartBody: " + multipartBody);
- console.log("multipartBody length: " + multipartBody.length);
- //client = http.request(pPort, pHost);
- /* headers copied from a browser request logged in wireshark */
- //'POST', '/cgi-bin/upload',
- var post_options = {
- host: pHost,
- port: pPort,
- path: '/cgi-bin/upload',
- method: 'POST',
- headers: {
- 'Accept': 'text/html, */*',
- 'Accept-Encoding': 'identity',
- 'User-Agent': 'Mozilla/3.0 (compatible; Indy Library)',//'Node.JS',
- 'Connection': 'keep-alive',
- 'Content-Type': 'multipart/form-data; boundary=' + boundary,
- 'Content-Length': multipartBody.length
- }
- };
- console.log('post_options:'+ JSON.stringify(post_options));
- var request1 = http.request(post_options, function (res) {
- //console.log('STATUS: ${res.statusCode}');
- //console.log('HEADERS: ${JSON.stringify(res.headers)}');
- res.setEncoding('utf8');
- var h1Resp = "H1 response not found";
- res.on('data', function (chunk) {
- var chunkStr = chunk.toString();
- //console.log("onData chunkStr: " + chunkStr);
- var ind1 = chunkStr.indexOf("<h1>");
- var ind2 = chunkStr.indexOf("</h1>");
- if (ind1 != -1) {
- h1Resp = chunkStr.substring(ind1 + 4, ind2);
- }
- return callback(null, {
- h1_resp: "File has been uploaded"
- });
- });
- }
- );
- request1.on('error', function (err) {
- console.log("Error event occured. Err: " + util.inspect(err));
- callback(err, {h1_resp: ''});
- });
- request1.write(multipartBody);
- request1.end();
- },
- /* unused function */
- uploadHTTP: function (pFileName, pUsername, pPassword, pHost, pPort, pMimeType, pOriginalFileName, callback) {
- /*console.log(pFileName);
- console.log(pUsername);
- console.log(pPassword);
- console.log(pHost);
- console.log(pPort);*/
- var fs = require("fs");
- var data = null; // надо правильно обрабаотывать ошибку если файл не найден!
- try {
- data = fs.readFileSync("upload/" + pFileName);
- } catch (e) {
- console.error("File not found");
- return callback(e, {h1_resp: ''});
- }
- var client;
- var request;
- //var data = "4090440380500854 46066184 5028602486509006 618927954312334113874277740948824551711527614232";
- var auth = "Basic " + new Buffer(pUsername + ":" + pPassword).toString("base64");
- /* As per http://www.w3.org/Protocols/rfc1341/7_2_Multipart.html */
- var crlf = "\r\n",
- boundary = '--------120315120542026', // Boundary: "--" + up to 70 ASCII chars + "\r\n"
- delimiter = "--" + boundary,
- preamble = "", // ignored. a good place for non-standard mime info
- epilogue = ""; // ignored. a good place to place a checksum, etc
- //application/octet-stream
- console.log("uploadHTTP pOriginalFileName: " + pOriginalFileName);
- var headers = [
- 'Content-Disposition: form-data; name="userfile"; filename="' + pOriginalFileName + '"' + crlf,
- //'Content-Type: application/octet-stream' + crlf,
- //'Content-Type: ' + pMimeType + crlf
- 'Content-Type: application/octet-stream' + crlf
- ],
- //bodyPart = headers.join('') + crlf + data.toString(),
- //encapsulation = delimiter + crlf + bodyPart,
- closeDelimiter = delimiter + "--",
- multipartBody; // = preamble + encapsulation + closeDelimiter + epilogue + crlf /* node doesn't add this */;
- multipartBody = Buffer.concat([
- new Buffer(preamble + delimiter + crlf + headers.join('') + crlf),
- data,
- new Buffer(crlf + closeDelimiter + epilogue + crlf)]
- );
- //console.log("multipartBody: " + multipartBody);
- console.log("multipartBody length: " + multipartBody.length);
- //client = http.request(pPort, pHost);
- /* headers copied from a browser request logged in wireshark */
- //'POST', '/cgi-bin/upload',
- var post_options = {
- host: pHost,
- port: pPort,
- path: '/cgi-bin/upload',
- method: 'POST',
- headers: {
- 'Accept': 'text/html, */*',
- 'Accept-Encoding': 'identity',
- 'User-Agent': 'Mozilla/3.0 (compatible; Indy Library)',//'Node.JS',
- 'Authorization': auth,
- 'Connection': 'keep-alive',
- 'Content-Type': 'multipart/form-data; boundary=' + boundary,
- 'Content-Length': multipartBody.length
- }
- };
- var request1 = http.request(post_options, function (res) {
- //console.log('STATUS: ${res.statusCode}');
- //console.log('HEADERS: ${JSON.stringify(res.headers)}');
- res.setEncoding('utf8');
- var h1Resp = "H1 response not found";
- res.on('data', function (chunk) {
- var chunkStr = chunk.toString();
- //console.log("onData chunkStr: " + chunkStr);
- var ind1 = chunkStr.indexOf("<h1>");
- var ind2 = chunkStr.indexOf("</h1>");
- if (ind1 != -1) {
- h1Resp = chunkStr.substring(ind1 + 4, ind2);
- }
- return callback(null, {
- h1_resp: h1Resp
- });
- });
- /*res.on('end', function() {
- console.log('End of response event occured');
- return callback(null, {
- h1_resp: h1Resp
- });
- });*/
- /*res.on('error', function (err) {
- console.log("ERR123: " + err);
- return callback(err, {
- h1_resp: ''
- });
- });*/
- }
- );
- console.log("auth: " + auth);
- request1.on('error', function (err) {
- console.log("Error event occured. Err: " + util.inspect(err));
- callback(err, {h1_resp: ''});
- });
- /*request1.setTimeout(10000, function(err){
- console.log("REQUEST TIMEOUT");
- callback(err, {h1_resp: ''});
- });*/
- /*request1.on('response', function (response) {
- console.log('response');
- response.setEncoding('utf8');
- response.on('data', function (chunk) {
- //console.log('Response: ' + util.inspect(chunk.toString()));
- var chunkStr = chunk.toString();
- var ind1 = chunkStr.indexOf("<h1>") + 4;
- var ind2 = chunkStr.indexOf("</h1>");
- var h1Resp = chunkStr.substring(ind1, ind2);
- callback(null, {
- h1_resp: h1Resp
- });
- });
- response.on('end', function () {
- console.log("end");
- });
- });*/
- request1.write(multipartBody);
- request1.end();
- }
- };
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement