Sending POST request to a django server

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

Hey all,

Not sure if this is the right place to ask this question, but I’m attempting to send some json data from godot to a django server. The godot-side code looks a bit like this:

var obj_to_send = {
    "field": "some data"
}

var SERVER_ADDRESS = "http://localhost:8000/django_app_name/upload"
$HTTPRequest.request(SERVER_ADDRESS, PoolStringArray(), true, HTTPClient.METHOD_POST, JSON.print(obj_to_send))

However, the django server doesnt receive anything. There isn’t even a message about a connection being made–its just nothing. Does anyone know what I could be doing wrong?

Also, if this is the wrong place to ask, please let me know where would be a better place.

Any help is appreciated.

I should add that when checking for what $HTTPRequest.request() returns, I get OK.

Bush2Tree | 2020-05-15 02:03

:bust_in_silhouette: Reply From: njamster

Not sure if this is the right place to ask this question

It is. :slight_smile:

However, the django server doesnt receive anything.

First of, the code you provided misses a couple of things:

  1. a closing parenthesis ) in the end of the last line
  2. the value of SERVER_ADDRESS (you only define server_adddress)
  3. the value of value, thus the value of "field"

However, your problem is simply with the value of server_address:

  1. Godot apparently doesn’t resolve localhost - so use the ip-address instead
  2. You don’t define a port number, by default django runs on port 8000

So the following should work:

var server_address = "http://127.0.0.1:8000/django_app_name/upload"

Works perfectly! Thanks for the help!
I also fixed up my example code so that it actually works.

Bush2Tree | 2020-05-15 18:05