Hi guys,
I keep it simple. I did a regular JSON post on a rest API without any problems for months.
UnityWebRequest req = UnityWebRequest.Post("https://<API URL>?key=" + <KEY>, bodyData);
Now we switched to a simple cloud server. Testing with Postman is successful. Still, I get the following errors:
UnityWebRequest req = UnityWebRequest.Post("http://<IPv4>", bodyData);
if = http://195.XXX.XXX.XX β Cannot connect to destination host
if = http://195.XXX.XXX.XX:3000 β HTTP/1.1 400 Bad Request
Am I missing something here? Are there any preconditions I need to be aware of? Appreciate any help on this topic!
Good to see you curl / Postmanned it first⦠now you have to find out how that request differs. A proxy such as Charles can be helpful here.
As with all network code, get it working with Postman or curl first. That makes it NOT a Unity problem. Solve the networking first. You must solve that or anything else is irrelevant.
Once you have that working, then try and port it to UnityWebRequest. If it still doesn't work, one handy debug solution is to hook up a proxy like Charles and compare the functioning output from Postman / curl to the output from Unity, and from that reason about where your issues are.
Itβs likely just some encoding or header issue that varies between the two stacks.
1 Like
Agreed with Kurt, this may help too https://support.unity.com/hc/en-us/articles/115002917683-Using-Charles-Proxy-with-Unity The important part to remember in your case is to install the Charles root certificate from the Help menu, and REBOOT
2 Likes
Got it working. Will not post the actual reason because - as in most cases - it was just a human mistake. Sorry for taking your time and thanks for your help!
1 Like