I've been trying to perform a simple request from various sites but so far I've had no success. I used the example at the http request section of the docs, but I still can't retrieve the results I want. More specifically I tried the following:
onready var http= $HTTPRequest # get the httprequest node
var url = "http://bark.phon.ioc.ee/punctuator/" # the url I am trying to retrieve info from
_make_post_request(url, ["text:this is a test"], false)
func _on_HTTPRequest_request_completed(result, response_code, headers, body):
var json = JSON.parse(body.get_string_from_utf8())
func _make_post_request(url, data_to_send, use_ssl):
# Convert data to json string:
var query= JSON.print(data_to_send)
# Add 'Content-Type' header:
var headers = ["Content-Type: application/json"]
http.request(url, headers, use_ssl, HTTPClient.METHOD_POST, query)
I don't understand how I am supposed to get results from this. What do I include in the
data_to_send variable? A list? A dictionary? And what format should I put it in?
Lastly, how do I print the result?
Sidenote: I was able to make this work using Python and the requests module in particular. I used a POST request and it fetched the data I wanted.