Why can't I send a request?

var https = require('https'); https.request({ hostname: 'script.google.com', path: '/macros/s/AKfycbwxPZTx1yOVGmVADtbvHScQqplz49knom4t_fCTHliQx9oaN4I/exec?p=123&p_1=11&p_2=22&p_3=33&p_4=44&p_5=55' }, function(res) { console.log("statusCode: ", res.statusCode); res.on('data', function(d) { process.stdout.write(d); } ); }).on('error', function(e) { console.error(e); }).end(); 

Gives out

 statusCode: 302 <HTML> <HEAD> <TITLE>Moved Temporarily</TITLE> </HEAD> <BODY BGCOLOR="#FFFFFF" TEXT="#000000"> <H1>Moved Temporarily</H1> The document has moved <A HREF="https://www.google.com/accounts/ServiceLogin?ser vice=wise&amp;passive=1209600&amp;continue=https://script.google.com/macros/s/AK fycbwxPZTx1yOVGmVADtbvHScQqplz49knom4t_fCTHliQx9oaN4I/exec?p%3D123%26p_1%3D11%26 p_2%3D22%26p_3%3D33%26p_4%3D44%26p_5%3D55&amp;followup=https://script.google.com /macros/s/AKfycbwxPZTx1yOVGmVADtbvHScQqplz49knom4t_fCTHliQx9oaN4I/exec?p%3D123%2 6p_1%3D11%26p_2%3D22%26p_3%3D33%26p_4%3D44%26p_5%3D55">here</A>. </BODY> </HTML> 

Closed due to the fact that off-topic participants Dmitriy Simushev , aleksandr barakin , cheops , Streletz , D-side 24 May '16 at 15:20 .

It seems that this question does not correspond to the subject of the site. Those who voted to close it indicated the following reason:

  • "The question is caused by a problem that is no longer reproduced or typed . Although similar questions may be relevant on this site, solving this question is unlikely to help future visitors. You can usually avoid similar questions by writing and researching a minimum program to reproduce the problem before publishing the question. " - Dmitriy Simushev, aleksandr barakin, cheops, Streletz, D-side
If the question can be reformulated according to the rules set out in the certificate , edit it .

  • error was in authorization with google - MackD

1 answer 1

The bottom line is that the server responds with a redirect. You should bear this in mind that if there is an appropriate response-code, you should go to the url address, which corresponds to the Location header from the answer.

  'use strict' const https = require('https'); let url = 'https://script.google.com/macros/s/AKfycbwxPZTx1yOVGmVADtbvHScQqplz49knom4t_fCTHliQx9oaN4I/exec?p=123&p_1=11&p_2=22&p_3=33&p_4=44&p_5=55'; function doRequest(url) { https.get(url, (res) => { if (res.statusCode >= 300 && res.statusCode <= 400 && res.headers.location) { doRequest(res.headers.location); } res.on('data', (d) => { process.stdout.write(d); }); }).on('error', (e) => { console.error(e); }); } doRequest(url); 
  • it doesn't work either - MackD
  • On js, everything is fine <script type = "text / javascript"> var script = document.createElement ('script'); script.type = 'text / javascript'; script.src = ' script.google.com/macros/s/… '; document.getElementsByTagName ("head") [0] .appendChild (script); function gotit (data) {console.log (data); document.body.appendChild (document.createTextNode (data)); } </ script> - MackD
  • @MackD Why? What mistake? It works for me. Version node 6.1.0 - nakhodkiin
  • It works, it works, but Google’s table is empty - MackD
  • And maybe the reason is due to the fact that I run it from a local computer? - MackD