UrlFetch with custom user-agent string?

后端 未结 2 1106
不知归路
不知归路 2021-01-04 01:48

Is it possible to change the user-agent string used with Google Apps Script UrlFetchApp.fetch requests?

This discussion from 2010 insinuates that the Url

相关标签:
2条回答
  • 2021-01-04 02:03

    You can send header information with UrlFetchApp in this way:

    var url = "http://mymagentohost/api/rest/products?limit=2"
    
    var params = { 
      headers: { 'Content-Type': "application/json", 'Accept': "application/json",
                 'User-Agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/71.0.3578.98 Safari/537.36'},
      muteHttpExceptions: true,
      method: "GET",
      contentType: "application/json",
      validateHttpsCertificates: false,
    };
    
    var response = UrlFetchApp.fetch(url, params);
    

    Just add the user agent information in the headers section. Hope it helps!

    Credit goes out to: Aditya Advani

    0 讨论(0)
  • 2021-01-04 02:16

    This is not possible today. Please log an enhancement request on the Issue Tracker with your use cases so this can be reviewed and considered.

    0 讨论(0)
提交回复
热议问题