{"id":1331,"date":"2017-10-10T18:57:05","date_gmt":"2017-10-10T19:27:05","guid":{"rendered":"https:\/\/mind4y.com\/itstuff\/?p=1331"},"modified":"2020-03-19T23:25:15","modified_gmt":"2020-03-19T23:55:15","slug":"nodejs-https-quicksample","status":"publish","type":"post","link":"https:\/\/ultering.com\/it4us\/?p=1331","title":{"rendered":"NODEJS: HTTPS &#8211; QUICKSAMPLE"},"content":{"rendered":"<p>A sample of creating a get request using nodejs on https<\/p>\n<pre>let https = request('https');\r\nconst options = {\r\n  hostname: 'www.panda.tv',\r\n  path: 'ajax_chatinfo?roomid=89757',\r\n  headers: { 'User-Agent': 'Mozilla\/5.0' }\r\n};\r\nconsole.log('generated options' + options);\r\nconst req = https.get(options, (res) =&gt; {\r\n\tlet body = '';\r\n\tconsole.log('Status:', res.statusCode);\r\n\tconsole.log('Headers:', JSON.stringify(res.headers));\r\n\tres.setEncoding('utf8');\r\n\tres.on('data', (chunk) =&gt; body += chunk);\r\n\tres.on('end', () =&gt; {\r\n\t\tconsole.log('Successfully processed HTTPS response');\r\n\t\t\/\/ If we know it's JSON, parse it\r\n\t\tif (res.headers['content-type'] === 'application\/json') {\r\n\t\t\tbody = JSON.parse(body);\r\n\t\t}\r\n\t\tconsole.log('response:['+body+']');\r\n\t\tcallback(null, body);\r\n\t});\r\n});\r\nreq.on('error', callback);\r\nreq.end();\r\n<\/pre>\n<!--CusAds0-->\n<div style=\"font-size: 0px; height: 0px; line-height: 0px; margin: 0; padding: 0; clear: both;\"><\/div>","protected":false},"excerpt":{"rendered":"<p>A sample of creating a get request using nodejs on https let https = request(&#8216;https&#8217;); const options = { hostname: &#8216;www.panda.tv&#8217;, path: &#8216;ajax_chatinfo?roomid=89757&#8217;, headers: { &#8216;User-Agent&#8217;: &#8216;Mozilla\/5.0&#8217; } }; console.log(&#8216;generated options&#8217; + options); const req = https.get(options, (res) =&gt; { let body = &#8221;; console.log(&#8216;Status:&#8217;, res.statusCode); console.log(&#8216;Headers:&#8217;, JSON.stringify(res.headers)); res.setEncoding(&#8216;utf8&#8217;); res.on(&#8216;data&#8217;, (chunk) =&gt; body += chunk); &#8230; <a href=\"https:\/\/ultering.com\/it4us\/?p=1331\" class=\"more-link\">Read More<span class=\"screen-reader-text\"> &#8220;NODEJS: HTTPS &#8211; QUICKSAMPLE&#8221;<\/span> &raquo;<\/a><\/p>\n","protected":false},"author":2,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"_bbp_topic_count":0,"_bbp_reply_count":0,"_bbp_total_topic_count":0,"_bbp_total_reply_count":0,"_bbp_voice_count":0,"_bbp_anonymous_reply_count":0,"_bbp_topic_count_hidden":0,"_bbp_reply_count_hidden":0,"_bbp_forum_subforum_count":0,"footnotes":""},"categories":[26],"tags":[10,27],"class_list":["post-1331","post","type-post","status-publish","format-standard","hentry","category-javascript","tag-javascript","tag-nodejs"],"_links":{"self":[{"href":"https:\/\/ultering.com\/it4us\/index.php?rest_route=\/wp\/v2\/posts\/1331","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/ultering.com\/it4us\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/ultering.com\/it4us\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/ultering.com\/it4us\/index.php?rest_route=\/wp\/v2\/users\/2"}],"replies":[{"embeddable":true,"href":"https:\/\/ultering.com\/it4us\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=1331"}],"version-history":[{"count":1,"href":"https:\/\/ultering.com\/it4us\/index.php?rest_route=\/wp\/v2\/posts\/1331\/revisions"}],"predecessor-version":[{"id":2643,"href":"https:\/\/ultering.com\/it4us\/index.php?rest_route=\/wp\/v2\/posts\/1331\/revisions\/2643"}],"wp:attachment":[{"href":"https:\/\/ultering.com\/it4us\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=1331"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/ultering.com\/it4us\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=1331"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/ultering.com\/it4us\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=1331"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}