I was given this simple script in python
import requests
val = "id"
data = {
'val': val,
'type': '1'
}
session = requests.session()
response = session.post('https://www.someweb.com/modules/output/ajax.check_results.php', data=data)
print(response.json())
For security reasons I am not allowed to reveal the correct url.
I do not know python (I can run above code on my computer and it works perfectly) so I wanted to port the code to Google Application Script. Currently it looks like that
function getResults() {
var url = 'https://www.someweb.com/modules/output/ajax.check_results.php';
var data = {
'val': 'id',
'type': '1'
}
var options = {
"method": "post",
// "headers": headers,
"data": data
};
var response = UrlFetchApp.fetch(url, options);
Logger.log(response.getContent);
Logger.log(response);
Logger.log(response.getAllHeaders());
Logger.log(response.getResponseCode());
Logger.log(response.getContentText());
//Logger.log(JSON.parse(response.getContent()));
//Logger.log(JSON.parse(response.getContentText()));
//Logger.log(JSON.parse(response));
}
The output looks like that
2:47:22 PM Notice Execution started
2:47:22 PM Info function () { [native code] }
2:47:22 PM Info
2:47:22 PM Info {Content-Type=text/html; charset=UTF-8, Expires=Thu, 19 Nov 1981 08:52:00 GMT, Date=Sun, 24 Jan 2021 13:47:22 GMT, Set-Cookie=PHPSESSID=ibdotvlrrec1q6glnbe8i0iu23; path=/, Server=Apache/2.4.38 (Debian), Cache-Control=private, must-revalidate, Content-Length=0, Pragma=no-cache, keep-alive=timeout=5, max=100, Connection=Keep-Alive}
2:47:22 PM Info 200.0
2:47:22 PM Info
2:47:23 PM Notice Execution completed
the commented Loggers give me that
3:14:03 PM Error SyntaxError: Unexpected end of JSON input getResults @
I think that the issue is that Google Script takes a second to finish but python takes 14 seconds. It waits to get the results.
Someone could help how to make Google Script to get the results too?
question from:
https://stackoverflow.com/questions/65871676/how-to-get-results-from-this-particular-post-http-call-in-google-script-works 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…