fsNetworkHttpRequestPost for Xbox does not work

Version: SU14/ Xbox

Frequency: Consistently

Severity: Blocker

Context: Stand alone WASM module installed through Marketplace (developer account)

Bug description: I am using fsNetworkHttpRequestPost function to send text data to the server, in response - server returns int number of the database record. While on PC it works properly in any way (installed through marketplace or community, in online or offline mode), it does not seem to send anything on Xbox - at least PHP script does not capture any data.

I have a guess that WASM data exchange does not work if user have no
Xbox Live Gold subscription active (i.e. online gaming features). Or maybe it’s issue in my code.

Repro steps: run sendLiveryTitle function, server should return “14” as text response but that does not happen.

void sendLiveryTitle() {

	char* _ATCtype = "Boeing";
	char* _ATCmodel = "FA18E";
	char* _ATCtitle = "Boeing F/A 18E Super Hornet Asobo";

	FsNetworkHttpRequestParam param;

	param.headerOptionsSize = 1;
	param.headerOptions = (char**)calloc(1, sizeof(char*));

	char headerContentType[32] = "accept: text/html";
	param.headerOptions[0] = headerContentType;

	const unsigned dataSize = 2048;
	char cData[2048];
	sprintf(cData, "model=%s&type=%s&title=%s", _ATCmodel, _ATCtype, _ATCtitle);

	param.dataSize = strlen(cData);
	param.postField = cData;

	fsNetworkHttpRequestPost("https://touching.cloud/AirshowAssistant/aircraft-list.php", &param, HttpPost_TitleID, nullptr);

	free(param.headerOptions);
}

static void HttpPost_TitleID(FsNetworkRequestId requestId, int errorCode, void* userData)
{
	DWORD aircraftDatabaseID = check_named_variable("TC_AIRSHOW_AIRCRAFT_DATABASE_ID");

	if (errorCode != 200)
	{
		set_named_variable_value(aircraftDatabaseID, 0);
		return;
	}

	unsigned char* data = fsNetworkHttpRequestGetData(requestId);

	char val[256];
	snprintf(val, sizeof(val), "%s", data);

	set_named_variable_value(aircraftDatabaseID, atof(val));
}

Hello @thealx

Did you check if the returned request id was valid and if fsNetworkHttpRequestGetErrorCode was returning an error code?

Regads,
Sylvain

I haven’t tried to debug it yet as will be able to try something only next Monday due to current WASM update schedule for Xbox

Hi,

As @FlyingRaccoon said, the problem in your code lies in the error code check. I have tried your package and received a 206 error code, which is a valid and success one (206 Partial Content).

I assume the code you have posted in your first message is the one you use, so the line

if (errorCode != 200)

is wrong in your case.

I advice you to filter each error code with a specific behavior, or if it is not necessary, accept all 2XX error codes as a success.

Best Regards
Maxime / Asobo

3 Likes

An HTTP 206 in this POST scenario would be an error, as they’re not performing range requests. I’d be curious to see the entire HTTP conversation if available.

@FlyingRaccoon @Arzop I have added some debug code on the server side and can provide additional information. Unrelated parameters (like paths) where removed. Very same add-on version was tested, which injested into marketplace and linked with my dev account, same aircraft, SU14 latest update.

You can notice some differences (like HTTP_CONTENT_RANGE > HTTP_RANGE), but most important - POST array is empty. Either fsNetworkHttpRequestPost does not work properly or char pointers not processed by Xbox c++ compiler/environment correctly (I have slightly different way of text passing to the function), but aren’t there will be all three values passed inside of POST request as empty strings?

Will try to apply some changes and test them next week, but maybe you will have a guess about issue.

PC:

POST: Array
(
    [model] => ATCCOM.AC_MODEL_FA18E.0.text
    [type] => Boeing
    [title] => Boeing F/A 18E Super Hornet Asobo
)

GET: Array
(
)

SERVER: Array
(
    [HTTP_AUTHORIZATION] => 
    [HTTPS] => on
    [HTTP_CONTENT_RANGE] => bytes 0-85/86
    [HTTP_USER_AGENT] => KittyHawk/0.9 (Windows; Desktop; Client/0.1)
    [HTTP_ACCEPT_ENCODING] => identity
    [HTTP_ACCEPT] => text/html
    [CONTENT_LENGTH] => 86
    [CONTENT_TYPE] => application/x-www-form-urlencoded
    [PATH] => /usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin
    [SERVER_SIGNATURE] => <address>Apache/2.4.18 (Ubuntu) Server at touching.cloud Port 443</address>

    [REQUEST_SCHEME] => https
    [CONTEXT_PREFIX] => 
    [REMOTE_PORT] => 50972
    [GATEWAY_INTERFACE] => CGI/1.1
    [SERVER_PROTOCOL] => HTTP/1.1
    [REQUEST_METHOD] => POST
    [QUERY_STRING] => 
)

apache_request_headers: Array
(
    [Content-Range] => bytes 0-85/86
    [User-Agent] => KittyHawk/0.9 (Windows; Desktop; Client/0.1)
    [Accept-Encoding] => identity
    [accept] => text/html
    [Content-Length] => 86
    [Content-Type] => application/x-www-form-urlencoded
)

XBOX:

POST: Array
(
)

GET: Array
(
)

SERVER: Array
(
    [HTTP_AUTHORIZATION] => 
    [HTTPS] => on
    [HTTP_CONNECTION] => Keep-Alive
    [HTTP_ACCEPT] => text/html
    [HTTP_RANGE] => bytes=0-85
    [HTTP_USER_AGENT] => KittyHawk/0.9 (Windows; Desktop; Client/0.1)
    [CONTENT_LENGTH] => 86
    [PATH] => /usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin
    [SERVER_SIGNATURE] => <address>Apache/2.4.18 (Ubuntu) Server at touching.cloud Port 443</address>

    [REQUEST_SCHEME] => https
    [CONTEXT_PREFIX] => 
    [REMOTE_PORT] => 50974
    [GATEWAY_INTERFACE] => CGI/1.1
    [SERVER_PROTOCOL] => HTTP/1.1
    [REQUEST_METHOD] => POST
    [QUERY_STRING] => 
)

apache_request_headers: Array
(
    [Connection] => Keep-Alive
    [Accept] => text/html
    [Range] => bytes=0-85
    [User-Agent] => KittyHawk/0.9 (Windows; Desktop; Client/0.1)
    [Content-Length] => 86
)