UrlFetch与自定义用户代理字符串? [英] UrlFetch with custom user-agent string?

查看:82
本文介绍了UrlFetch与自定义用户代理字符串?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

是否可以更改用于Google Apps脚本的用户代理字符串 UrlFetchApp.fetch 请求?



2010年的此讨论暗示Google Apps中的UrlFetch模块脚本支持将 User-Agent 头添加到可选的集合中,就像Google App Engine的UrlFetch模块一样。但是, GAS文档没有说明这一点。我做的测试脚本也显示它不起作用。



测试脚本:

  function testUserAgentString(){
var page;
尝试{
page = UrlFetchApp.fetch('http://www.myuseragent.net/',{headers:{User-Agent:Mozilla / 5.0(Windows; U; Windows NT 5.1; en-GB; rv:1.8.1.6)Gecko / 20070725 Firefox / 2.0.0.6}})。getContentText();
Logger.log(page);
} catch(_){}
}

日志输出(减去不相关HTML)为:



Mozilla / 5.0(compatible; GoogleDocs; script; + http://docs.google.com)

这是GAS执行UrlFetch请求时使用的默认用户代理字符串。



上午我错过了什么或做错了什么?



编辑:目前我无法做到这一点,所以我放了一个增强版请求

解决方案

今天是不可能的。请使用您的使用案例在问题跟踪器上登录一项增强请求这可以被审查和考虑。

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

This discussion from 2010 insinuates that the UrlFetch module in Google Apps Script supports adding the User-Agent header to the optional headers collection, like the UrlFetch module of Google App Engine does. However, the GAS documentation states nothing about this. A test script I made also shows it doesn't work.

Test script:

function testUserAgentString(){
  var page;
  try {
    page = UrlFetchApp.fetch('http://www.myuseragent.net/', {headers: {"User-Agent": "Mozilla/5.0 (Windows; U; Windows NT 5.1; en-GB; rv:1.8.1.6) Gecko/20070725 Firefox/2.0.0.6"}}).getContentText();
    Logger.log(page);
  } catch(_) {}
}

Log output (minus irrelevant HTML) was:

Mozilla/5.0 (compatible; GoogleDocs; script; +http://docs.google.com)

which is the default user-agent string used when doing UrlFetch requests by GAS.

Am I missing something or doing something wrong?

Edit: As this is currently not possible, I placed an enhancement request on the Issue Tracker, per Arun's suggestion.

解决方案

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.

这篇关于UrlFetch与自定义用户代理字符串?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆