如何使用凭证使用UrlFetchApp? Google脚本 [英] How to use UrlFetchApp with credentials? Google Scripts

查看:509
本文介绍了如何使用凭证使用UrlFetchApp? Google脚本的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我尝试使用Google脚本UrlFetchApp访问使用基本用户名和密码的网站。只要我连接到该网站,就会出现一个需要验证的弹出窗口。我知道登录名和密码,但我不知道如何在UrlFetchApp中传递它们。


$ b


var response = UrlFetchApp.fetch( htp://00.000.000.000:0000 /);

Logger.log(response.getContentText(UTF-8));

目前运行该代码返回拒绝访问。出于安全原因,以上代码不包含我连接的实际地址。代码示例中的所有http都缺少t,因为它们被检测为链接,并且Stackoverflow不允许我提交两个以上的链接。



我如何通过登录和密码以及我的请求?无论如何,我还可以在登录后继续我的会话吗?或者我的下一个UrlFetchApp请求是否会从另一台Google服务器发送,要求我再次登录?

这里的目标是登录到Googles网络基础设施后面的网站,以便它可以作为代理,然后我需要发出另一个UrlFetchApp请求到相同的地址像这样:


var response = UrlFetchApp.fetch(htp://00.000.000.000:0000 / vuze / rpc?json = { 方法: 洪流 - 添加, 论据:{ 文件名: HTP://vodo.net/media/torrents/anything.torrent, 下载目录:C:\temp }});

Logger.log(response.getContentText(UTF-8));


解决方案

这个问题已经在另一个地方回答了。
以下是总结:

Bruce Mcpherson


 基本认证看起来像这样... 
var options = {};
options.headers = {Authorization:Basic+ Utilities.base64Encode(username +:+ password)};


Lenny Cunningham


  //添加基本授权////////////////// ////////////////////////////////////////////////// ////////////////////// 

var USERNAME = PropertiesService.getScriptProperties()。getProperty('username');
var PASSWORD = PropertiesService.getScriptProperties()。getProperty('password');

var url = PropertiesService.getScriptProperties()。getProperty('url'); //////////////////////////转发

端口到WebRelay

  var headers = {
Authorization:Basic+ Utilities.base64Encode(USERNAME +':'+ PASSWORD)
};

var params = {
method:GET,
headers:headers
};

var reponse = UrlFetchApp.fetch(url,params);



I am trying to use Google Scripts UrlFetchApp to access a website with a basic username and password. As soon as I connect to the site a popup appears that requires authentication. I know the Login and Password, however I do not know how to pass them within the UrlFetchApp.

var response = UrlFetchApp.fetch("htp://00.000.000.000:0000/‎");
Logger.log(response.getContentText("UTF-8"));

Currently running that code returns "Access Denied". The above code does not contain the actual address I am connecting to for security reasons. A "t" is missing from all the "http" in the code examples because they are being detected as links and Stackoverflow does not allow me to submit more than two links.

How can I pass the Login and Password along with my request? Also is there anyway I can continue my session once I have logged in? Or will my next UrlFetchApp request be sent from another Google server requiring me to login again?

The goal here is to login to the website behind Googles network infrastructure so it can act as a proxy then I need to issue another UrlFetchApp request to the same address that would look something like this:

var response = UrlFetchApp.fetch("htp://00.000.000.000:0000/vuze/rpc?json={"method":"torrent-add","arguments":{"filename":"htp://vodo.net/media/torrents/anything.torrent","download-dir":"C:\temp"}}‎");
Logger.log(response.getContentText("UTF-8"));

解决方案

This question has been answered on another else where. Here is the summary:

Bruce Mcpherson

basic authentication looks like this...
    var options = {};
    options.headers = {"Authorization": "Basic " + Utilities.base64Encode(username + ":" + password)};

Lenny Cunningham

//Added Basic Authorization//////////////////////////////////////////////////////////////////////////////////////////

  var USERNAME = PropertiesService.getScriptProperties().getProperty('username');
  var PASSWORD = PropertiesService.getScriptProperties().getProperty('password');

  var url = PropertiesService.getScriptProperties().getProperty('url');//////////////////////////Forwarded

Ports to WebRelay

  var headers = {
    "Authorization" : "Basic " + Utilities.base64Encode(USERNAME + ':' + PASSWORD)
  };

  var params = {
    "method":"GET",
    "headers":headers
  };

var reponse = UrlFetchApp.fetch(url, params);

这篇关于如何使用凭证使用UrlFetchApp? Google脚本的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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