Godot API requests

:information_source: Attention Topic was automatically imported from the old Question2Answer platform.
:bust_in_silhouette: Asked By Fordem

I am trying to make an API call to an API which returns an XML document as the response. This request works fine in post man and with other languages but I am not sure how to get the XML file in godot. When I make the request it just returns 0 as the response and a bunch of comma separated numbers as the body which is confusing because I didn’t get that response on postman. Here is the code I am using to make the request.

func _on_LineEdit_text_entered(new_text):
$HTTPRequest.request("http://export.arxiv.org/api/query?search_query=all:electron&start=0&max_results=1")


func _on_HTTPRequest_request_completed(result, response_code, headers, body):
	print(result)

This Code works when making calls to APIs that return json values but im not sure how to get it working with an API that returns an XML

:bust_in_silhouette: Reply From: SteveSmith

A result of 0 means success. It sounds like it’s working, you just need to convert body (probably a PoolByteArray) to a string.

Ah that makes sense thank you, I hadnt heard of PoolByteArrays before. Do you know a way to convert it to a readable string or a link to a resource which might help me convert it?

Fordem | 2022-12-21 15:39

var s = body.get_string_from_utf8()

SteveSmith | 2022-12-21 16:12