Open gRegorLove opened 3 years ago
Bumping to make sure this was seen. cc @lguilbert
This local fix appears to be working and I think is less hacky than my earlier suggestions:
At line 71, added:
/**
* Workaround for HTTP 502 issue on login, when body is empty.
* Set body to empty {}
* @see https://help.claris.com/en/data-api-guide/#connect-database_log-in
* @see https://github.com/myFMbutler/myFMApiLibrary-for-PHP/issues/11
*/
if ($method === 'POST' && isset($options['json']) && empty($options['json'])) {
curl_setopt($ch, CURLOPT_POSTFIELDS, '{}');
$contentLength = false;
}
Hi.
Thanks for the review but: I'm no longer a part of Lesterius anymore; my access is closed. I'm not able to accept/declined this and I don't think this will happen from someone else.
I did a fork for myself. I added your fix here https://github.com/lguilbert/myFMApiLibrary-for-PHP/commit/dbecfec5592cfcda4f7361ba3edd174ee76300ed
Or you could do your own Fork too. Have a nice day.
I have run into an issue with the cURL requests when running version 1.1.0 under PHP 7.3.
When calling
login()
, CurlClient does not set a request body and sets the headerContent-Length: 0
. The problem is that when there's no request body, PHP7 (or the cURL lib itself) will add the headerTransfer-Encoding: chunked
. From my reading, it looks like Content-Length is supposed to be omitted when using chunked encoding.The combination of Content-Length and chunked encoding headers seems to cause the FM Data API endpoint to return an HTTP 502 error.
I tried a few different things. The simplest that got it to work was commenting out the line that sets the Content-Length header:
I also experimented with setting the body as
{}
as the FileMaker docs describe (though it does not seem to be required; login requests with no body do work) and removing the same line above. cURL correctly calculated and added the Content-Length header automatically.Original, faulty headers that result in HTTP 502:
Removing the line above generates these headers, which work:
Or, removing that line above and adding an else condition that defaults the body to empty JSON...
...generates these headers which also work:
I lean towards the second one to be in line with the FileMaker docs, though I'm not sure if that causes issues with earlier PHP / cURL lib versions, especially since it looks like you're still supporting PHP 5.6.