5

I use google app script (where we usually use almost raw js, without libs and etc). So I need to use proxy server (need dynamic-changing ip address).

But when i make request, proxy server calls back

This is a proxy server. Does not respond to non-proxy requests.

In common way, making http request in google app scrip seems like this:

 function make_some_request() {
  const url = 'https://www.google.com/';
  
  var headers = {
    "Content-Type" : "application/json; charset=utf-8",
  }
  
  var payload = []; // some data if we need post request
  
  var options = {
    "method"  : "POST",
    'headers' : headers,
    'payload' : JSON.stringify(payload)
  };
  
  try {
    
    var response = UrlFetchApp.fetch(url, options);
    return JSON.parse(response);
    
  } catch (error) {
    log("make_some_request", "ERROR: " + error);
  }
}

So, i can't understand what should i make with my request to use proxy server. How we make call through proxy server in common way (in raw HTTP). What headers or payload should i send to make this request a proxy-request?

P.S. as i know, google app script doesn't support another classes to make https requests. So all i have is almost raw HTTP.

Nikita Goncharov
  • 173
  • 2
  • 13
  • 2
    The return value from `UrlFetchApp.fetch(url,options)` is the Class HTTPResponse. See: [UrlFetchApp.fetch() documentation](https://developers.google.com/apps-script/reference/url-fetch/http-response?hl=en) If you want the raw content of the request, then you need to use the `getContent()` method: `response.getContent()` Your example is using `POST` and a url of `https://www.google.com/`. You'd need to use `GET` It's helpful to set `muteHttpExceptions` to true. `options.muteHttpExceptions = true;` which disables exceptions when a non-200 status code is returned. – Alan Wells Nov 01 '20 at 19:29
  • Thank you for answer. Yea, i understand about get/post. My question is not about response is about request. In other languages there is ready modules to make proxy request. Just need to set some parameters. But there is no such parameters or a class. So i wonder how to make proxy request – Nikita Goncharov Nov 01 '20 at 19:55
  • Using a proxy programmatically usually means you need a socket (not to be confused with a websocket) to connect to the proxy. The type of proxy (socks or http) determines the communications protocol used. [This answer](https://stackoverflow.com/a/38259076/367865) describes what an http proxy request looks like. – Ouroborus Nov 01 '20 at 21:03

0 Answers0