Attention | Topic was automatically imported from the old Question2Answer platform. | |
Asked By | hughes1992 |
Hello I am trying to request data from a URL on my local Laravel PHP server. The issue is that I can successfully connected to the page without any errors, response code is 200 all OK, and I receive no body response in Godot.
I can reach the page without any special tokens and reach it in the browser,
The response is a simple response I set up with
return response('Hello World', 200);
` prints hello world in text/plain with 200 status code. its as simple as it gets.
In godot this is my code to request the page…
var err = 0
var tries = 0
make_connection() ** MAKES A CONNECTION TO THE HOST SERVER HERE
if send_data:
var query = http.query_string_from_dict(send_data)
var header = ["Content-Type: application/x-www-form-urlencoded",
"Content-Length: " + str(query.length()),
"Accept: */*",
"Connection: keep-alive",
"Host: 127.0.0.1:8000"
]
if debug:
print(query)
err = http.request(HTTPClient.METHOD_POST,page,header,query)
else:
var header = ["Content-Type: application/x-www-form-urlencoded",
"Accept: */*",
"Connection: keep-alive",
"Host: 127.0.0.1:8000"
]
err = http.request_raw(HTTPClient.METHOD_POST,page,header,[])
if debug:
print("Requesting " + str(page))
# 0 is OK
if err != 0:
if debug:
print("Request to [ " + page + " ] failed with " + str(err))
prompt_to_connect()
else
*** MAKES IT HERE WITHOUT ANY ERRORS
while http.get_status() == HTTPClient.STATUS_REQUESTING:
http.poll()
OS.delay_msec(poll_delay)
tries += 1
if debug:
print("Requesting...." + str(http.get_status()))
if tries == 20:
print("Request failed.")
make_connection()
if debug:
print("Request status: " + str(http.get_status())) *** SAYS 5, CONNECTED
print("Pre Request HTTP Code: " + str(http.get_response_code()))
if http.has_response():
*** HAS A RESPONSE
print(str(http.poll()))
var raw_data = PoolByteArray()
print(str(http.poll()))
if debug:
print("Request response...")
print("Response Status: " + str(http.get_status())) **** 5 connected
print("Is Chunked? " + str(http.is_response_chunked())) *** brings back false
print("Response HTTP Code: " + str(http.get_response_code())) *** 200, OK
print("Response Length: " +str(http.get_response_body_length())) *** returns 0, no length body.
while http.get_status() == HTTPClient.STATUS_BODY: ***** this doesn't even get called, goes straight to STATUS_CONNECTED
print("Polling response data...")
print(str(http.poll()))
var chunk = http.read_response_body_chunk()
if chunk.size() == 0:
OS.delay_usec(poll_delay)
else:
raw_data = raw_data + chunk
** should print raw_data into an ascii string, but raw_data is null because there is a zero-length body response.
These are the response headers:
Host: 127.0.0.1:8000
Date: Fri, 21 Dec 2018 16:09:19 -0500
Connection: close
X-Powered-By: PHP/7.2.11
Cache-Control: no-cache, private
Date: Fri, 21 Dec 2018 21:09:19 GMT
Content-Type: text/plain; charset=UTF-8
Set-Cookie: XSRF-TOKEN=eyJpdiI6IktMc0dZbk9XSFgzdm56eUdSR1pnaGc9PSIsInZhbHVlIjoiaGJUUnBVQXNiUlZEeEd1czFzSkdMdklXQVYxZWdURU5acVMrNFJLZmt1SXU3WExcL0l4YXN3MjV1ZTgrbzhhUXEiLCJtYWMiOiJkNjA4OGU2ODlhYzNjODdiYWE5NzQ1NDZkOTIyMmEyNmM4YjQ5MmEzOTc2OTU2M2RlM2QwM2I3MjhjOTE4MmU0In0%3D; expires=Fri, 21-Dec-2018 23:09:19 GMT; Max-Age=7200; path=/
Set-Cookie: laravel_session=eyJpdiI6IkVLMGZ2VXRPR29XdkYzM2lIcTFBTHc9PSIsInZhbHVlIjoiWkcraUhremZSSkViQkVkYkhHNEo2d0UyNzlwSU9XS2dnTGtlQkFmU2lLWUlHdCs5QkJVSHJqblZvd3NabGFpaiIsIm1hYyI6ImRiZDA3N2E1ZTcyZGRiYjBmNjc1MjQyNmM4MThiZTQ2MTgxNjAzMjkwZjkzYThlMjhhODE5OWI0N2E1NmVmNTMifQ%3D%3D; expires=Fri, 21-Dec-2018 23:09:19 GMT; Max-Age=7200; path=/; httponly