FXServer PerformHttpRequest Error

Hi. I just did the switch over to FXServer and I am having an issue with PerformHttpRequest. This is the request I am trying to passfunction br_rp_UpdateCadList() SetTimeout(6000, function() PerformHttpRequest("my.website.page", function(err, text, headers) --print(text) br_rp_UpdateCadListTab(text) br_rp_UpdateCadList() end, 'POST', json.encode({ process = "updateall" })) end) end br_rp_UpdateCadList()

This used to work fine on CitizenMP.Server. I have no idea what it is doing now. The error this gives me isInvokeNative: execution failed: type must be object, but is array Error resuming coroutine: Execution of native 000000008e8cc653 in script host fa iled. stack traceback: [C]: in upvalue '_in' citizen:/scripting/lua/natives_server.lua:190: in function 'PerformHttpR equestInternal' citizen:/scripting/lua/scheduler.lua:233: in function 'PerformHttpReques t' s1.lua:296: in function <s1.lua:295>

Ive tried many other ways including the following and I still get the same error. I even put it in its own resource to try and isolate the function.

function wtf() PerformHttpRequest("https://www.google.com/", '') end wtf()

InvokeNative: execution failed: type must be object, but is array Error loading script s1.lua in resource rp2: Execution of native 000000008e8cc653 in script host failed. stack traceback: [C]: in upvalue '_in' citizen:/scripting/lua/natives_server.lua:190: in function 'PerformHttpRequestInternal' citizen:/scripting/lua/scheduler.lua:233: in function 'PerformHttpRequest' s1.lua:7: in function 'wtf' s1.lua:9: in main chunk Failed to load script s1.lua.

1 Like

Wellā€¦ I could have swore I was told before I didnā€™t need [ā€œContent-Typeā€] in there, as it would default to something, but adding in { ["Content-Type"] = 'application/json' } fixed the issue :face_with_thermometer:

1 Like

you need an empty table at least for headers currently

Yeah, not a problem. Just one of those things. Drove me crazy trying to figure out what the issue was though. :wink:

Can you show a working snippet for PerformHttpRequest() on FX, please?

PerformHttpRequest("website.com", function(err, text, headers) --print(text) br_rp_UpdateCadListTab(text) end, 'POST', json.encode({ process = "updateall" }), { ["Content-Type"] = 'application/json' })

1 Like

Actuallyā€¦ I never even looked at the response I was getting from that request. I just happened to look through it now and I am getting this error, because of the content-type headers I believe? Uhā€¦ any idea here? Not sure what to put for headers. I tried application/x-www-form-urlencoded, multipart/form-data, and text/html also. Not even sure if thats the problem.

[code]

406 Not Acceptable

Not Acceptable

An appropriate representation of the requested resource /test2.php could not be found on this ser ver.

Additionally, a 406 Not Acceptable error was encountered while trying to use an ErrorDocument to handle the request.

[/code]

Just pass {} if needed.

I tried that too, but then it gives the error from original post

Ah, thatā€™s probably concerning indeed - it defaults a Lua table to array in that caseā€¦ perhaps just pass { ["X-Dummy"]="1" } or so?

Same 406 error 20char20char

Iā€™ve tried the same exact thing on the citizenmp server and it works fine. Not sure why it doesnā€™t like fx

Are you sure your web server isnā€™t being picky when it comes to Accept headers?

I tried it with the proposed solution of using { ["Content-Type"] = 'application/json' } as the header and it works fine, it also works with {[''] = ''}, but Iā€™d recommend using the first as it is a valid header. There does seem to be a difference in what the first parameter returns, it used to be that it returned 0 when the request was succesful, but now it returns 200, which is actually the correct way.

It is strange that this issue occurs though, in the source code it is supposed to set an empty header when the header is empty:

function PerformHttpRequest(url, cb, method, data, headers)
		local t = {
			url = url,
			method = method or 'GET',
			data = data or '',
			headers = headers or {}
		}

		local d = json.encode(t)
		local id = PerformHttpRequestInternal(d, d:len())

		httpDispatch[id] = cb
	end

Did something change in the underlying native?

It is certainly possible. The only reason I didnt think it was an issue with my site was because it worked on the citizen server without error. Ive done some searching on the error, and Im not completely sure on what I should do to address it on my site.

Not sure if this would help in trying to figure out what is wrong, but this is the exchange of info shown by wireshark.
Send:Hypertext Transfer Protocol POST /test2.php HTTP/1.1\r\n Host: briglair.com\r\n User-Agent: curl/7.54.0-DEV\r\n Accept: */*\r\n Content-Type: text/html\r\n Content-Length: 25\r\n \r\n [Full request URI: http://briglair.com/test2.php] [HTTP request 1/1] [Response in frame: 11707] File Data: 25 bytes
Receive:Hypertext Transfer Protocol HTTP/1.1 406 Not Acceptable\r\n Date: Fri, 28 Jul 2017 22:52:46 GMT\r\n Server: Apache\r\n Content-Length: 384\r\n Connection: close\r\n Content-Type: text/html; charset=iso-8859-1\r\n \r\n [HTTP response 1/1] [Time since request: 0.024026000 seconds] [Request in frame: 11701] File Data: 384 bytes

This is probably an issue with your ā€˜Apacheā€™ configuration, this request is perfectly valid.

Thatā€™s what I figured, but I donā€™t know why it worked perfectly on CitizenMP vs this on FX. :worried: Itā€™s a web hosting service, so itā€™s not anything I setup either.

Not a big deal for me anymore anyway. I started using C# with SQL connector.