Hi everyone,
As a bit of background. I’m a game developer with a bit of web development experience. I’m using our company’s Wix site as a backend for storing information about our players and their stats in one of our games.
I’ve been trying to set up an account/login system for our game that can be accessed directly from our client with username and password functionality.
So far I’ve been using get functions in our http-functions call because I haven’t been able to get a Post or a Put call to work. Our needs for some particular functions mean I can’t use a GET call in this case.
I think it must be an issue on the web server’s end (maybe something I’m doing wrong?) because I tested my code from our client application with my own personal web server using
a PHP backend and I was able to access the POST data from the client form just fine.
Maybe I’m just unaware of how to access POST data from the request object but from what I’ve read in the documentation regarding POST it should be in the body portion of the request. However, when I make the call from our game client and output the entire request object the body is empty and there is no sign of my POST form data or anything.
Is there a second object parameter that my post function needs? How can I access data sent to this function via POST or a form? (to be clear, this data is not coming from our wix site it’s coming from an external client). Maybe I need to change the content-type in the header of the request somehow?
Here is a sample of my testing code:
Game client side Code in Unity (2020.1.14f1) (C#):
public static IEnumerator RegisterTest(string username, string password)
{
string url = $"www.OurCompanyWixSite. ca/_functions/Register";
WWWForm form = new WWWForm();
form.AddField("username", username);
form.AddField("password", password);
using (UnityWebRequest webRequest = UnityWebRequest.Post(url, form))
{
yield return webRequest.SendWebRequest();
if (webRequest.isNetworkError || webRequest.isHttpError)
{
Debug.LogError(webRequest.error);
Debug.Log(webRequest.downloadHandler.text);
}
else
{
Debug.Log(webRequest.downloadHandler.text);
}
}
ProceedToNextWebCall();
}
The code from http-functions (javascript):
import {ok , notFound, serverError } from 'wix-http-functions';
//...
export function post_Register(request){
{
let options = {
"headers":{
"Content-Type": "application/json"
}
};
options.body = request;
return ok(options);
}
}
the response is this the entire request object (I had to modify any links in here to post) is this (excluding a few details in case they are sensitive):
{
"functionName":"Register",
"path":[
],
"url":"http: //OurCompanyWixSite/_functions/Register",
"baseUrl":"http: //OurCompanyWixSite/_functions",
"method":"POST",
"body":{
},
"headers":{
"host":"www.OurCompanyWixSite. ca",
"user-agent":"UnityPlayer/2020.1.14f1 (UnityWebRequest/1.0, libcurl/7.52.0-DEV)",
"transfer-encoding":"chunked",
"accept":"*/*",
"accept-encoding":"identity",
"authorization": // an authorization ID is here,
"cid":"",
"content-type":"application/x-www-form-urlencoded",
"geoip_country_code":"CA",
"geoip_country_code3":"CAN",
"identities":"{\"identificationData\":{},\"signedToken\":\"/* A signed token ID is here */"}",
"requesturl":"_functions/Register",
"via":"1.1 google",
"x-cloud-trace-context": //Some ID is here,
"x-envoy-expected-rq-timeout-ms":"120000",
"x-forwarded-for": // 2 IPs are here,
"x-forwarded-proto":"http",
"x-newrelic-id": //Some ID is here,
"x-newrelic-transaction": //Some ID is here,
"x-original-authority":"com .wixpress.wixcode.wix-code-functions-public-dispatcher",
"x-real-ip": //real-ip is here,
"x-request-id": //request ID is here,
"x-unity-version":"2020.1.14f1",
"x-wix-aid": //aid ID is here,
"x-wix-artifact-id":"com .wixpress.wixcode.wix-code-functions-public-dispatcher",
"x-wix-authorization": //authorization is here
"x-wix-code-elementory-experiments":"{\"specs.wixCode.replaceBabelWithSwc\":\"true\"}",
"x-wix-code-forwarded-url":"http://www.OurCompanyWixSite. ca/_functions/Register",
"x-wix-code-instance-id": // instance ID is here,
"x-wix-code-owner-id": // Wix owner ID is here,
"x-wix-code-public-url":"http://www.OurCompanyWixSite. ca/_functions/Register",
"x-wix-country-code":"CA",
"x-wix-country-code3":"CAN",
"x-wix-data-tenant-id": //tenant ID is here,
"x-wix-ddos-entry-point":"nane1",
"x-wix-diag-ctx": //An ID is here
"x-wix-forwarded-url":"http://www.OurCompanyWixSite. ca/_functions/Register",
"x-wix-google-ccm":"1",
"x-wix-grid-app-id"://app id is here,
"x-wix-host-rewrite"://company website is here,
"x-wix-instance-id": //instance ID is here,
"x-wix-locale":"{\"locale\":\"en\"}",
"x-wix-meta-site-id": //Meta site ID is here,
"x-wix-region-code":"ON",
"x-wix-request-id"://Request ID is here,
"x-wix-route-account-settings-server":"rollout",
"x-wix-route-funnel-builder-service":"rollout",
"x-wix-route-seating-public":"rollout",
"x-wix-server-identity": //Server Identity is here
"x-wix-signed-token"://Token ID is here
"x-wix-site-revision":"1546",
"x-wix-use-cloud-data":"true",
"x-wix-use-data-edm-module":"false",
"x-wix-use-dstore":"true",
"x-wix-use-platformized-data-api":"false",
"x-wix-use-telemetry-logs":"false",
"x-wix-user-agent":"{\"ua\":\"Other\",\"os\":\"Unknown\",\"deviceClass\":\"Other\",\"engine\":\"Other\"}",
"x-wix-user-agent-info":"{\"ua\":\"Other\",\"os\":\"Unknown\",\"deviceClass\":\"Other\",\"engine\":\"Other\",\"uaDetails\":{\"name\":\"\"},\"osDetails\":{\"name\":\"\"},\"excludedSafariOrIOS\":false}",
"x-wix-view-mode":"Site"
},
"ip": //IP is here
}
The body portion of the request object seems to be empty.
If anyone has any idea what might be my issue I would greatly appreciate any help. If more information is needed please let me know! Maybe there is an npm package I could use instead if this doesn’t work?
Thank you!