我尝试使用 Google 应用脚本在我的 DirectEnergie 帐户中验证自己的身份。 当我使用 Chrome 将请求放在 POSTMAN 上时,它可以工作,但是当我尝试如下操作时,它会返回第一页的 HTML,而无需身份验证。
function getSumParr(){
var ss = SpreadsheetApp.getActiveSpreadsheet();
var sheet = ss.getSheets()[0];
url = "https://particuliers.direct-energie.com/mon-espace-client/?tx_deauthentification[login]=login&tx_deauthentification[password]=motdepasse&tx_deauthentification[form_valid]=1&tx_deauthentification[redirect_url]= "
var resultat = UrlFetchApp.fetch(url);
Logger.log(resultat);
}
当我跟踪 postman 的请求历史记录时,我得到了以下结果: 响应[303],响应[307]
有人知道如何解决这个问题吗?
最佳答案
您可能想查看有关 GET and POST Requests in Google Apps Script 的教程:
With Google Apps Script, you can easily create a Web App that serves HTML, JSON, XML or plain text output using the HTML service. When published as an app, the script gets a public URL that can be called using either GET or POST requests with parameters.
这是他们的代码片段:
function testPOST() {
var url = ScriptApp.getService().getUrl();
var payload =
{
"name" : "labnol",
"blog" : "ctrlq",
"type" : "post",
};
var options =
{
"method" : "POST",
"payload" : payload,
"followRedirects" : true,
"muteHttpExceptions": true
};
var result = UrlFetchApp.fetch(url, options);
if (result.getResponseCode() == 200) {
var params = JSON.parse(result.getContentText());
Logger.log(params.name);
Logger.log(params.blog);
}
}
此示例还遵循 documentation了解如何使用可选的高级参数发出获取 URL 的请求。
希望这有帮助。
关于javascript - Google 脚本 HTML 请求 - 发布,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/44524798/