'Capturing post data from C++ application in Codeigniter 4

I am upgrading our site from Codeigniter 3 to Codeigniter 4. So far it has been tedious, but mostly gone well. I am running into an issue now with a controller that will not recognize posted values from an app written in C++. This app has been working with CI 3 for many years now, but... well, CI4. I don't know all the details about the C++ app, but the developer assures me he is definitely using HTTP_VERB_POST to send the data to the controller. ----EDIT----- Here is the code from the C++ app that calls the controller in question:

subscriptioninfo = pSession->OpenRequest(CHttpConnection::HTTP_VERB_POST, address, NULL, NULL, NULL, NULL, INTERNET_FLAG_SECURE | INTERNET_FLAG_RELOAD | INTERNET_FLAG_DONT_CACHE);

I have created a view for the controller and CAN successfully Post values from a form using my browser.

However - Posting from the app 1) tells me the request method is GET and 2) NO values at all have been passed. It DOES however - send me the response I would expect if no values are passed to the controller......

After adding the following to my controller:

        header('Access-Control-Allow-Origin: *');
        echo $this->request->getMethod();
        echo "\n POST VARS = ";
        print_r($_POST);
        echo "\n GET VARS = ";
        print_r($_GET);
        echo "\n";

I get the following result:

get
 POST VARS = Array
(
)

 GET VARS = Array
(
)

Activation: No
Error: No parameters sent.

The last two lines (Activation and Error) are what I would expect to get from this controller if, indeed, no parameters are sent.

Oh - and no, I do not have CSRF (except for default Cookie based CSRF Protection) enabled in my CI 4 application.

Any ideas would be greatly appreciated!


I've tried a number of different things, and think the issue is that CI4 is not receiving the Content-Type header from the C++ app. It is explicitly set with this:

CString strHeaders = _T("Content-Type: application/x-www-form-urlencoded");

Here is a simple print of the headers received by both CI4 and CI3 on the same server. (I have copied my old CI3 app to a directory called 'dev' inside the Public directory of CI4.)

Headers from CI3 in Public folder

host: test.site.com
Accept: */*
Accept-Encoding: gzip, deflate, br
Accept-Language: en-US,en;q=0.9
Authorization: Basic XXXXXXXXXXXXXXXXXXXX
Content-Type: application/x-www-form-urlencoded
Cookie: ci_session=9do54stine1po2c0tren49gr17eq068g
User-Agent: CustomName
X-Forwarded-For: 96.68.149.126
X-Forwarded-Port: 443
X-Forwarded-Proto: https
Content-Length: 164
Connection: keep-alive

Response from CI3

Subscription number: 9999999999999999
Activation: No
Error: Activation Key does not exist.

Headers from CI4

host: test.site.com
Accept: */*
Accept-Encoding: gzip, deflate, br
Accept-Language: en-US,en;q=0.9
Authorization: Basic XXXXXXXXXXXXXXXXXXXX
Cookie: ci_session=g6v3qlgms2bv3ijv19hpl3cgnvnbg4kk
User-Agent: CustomName
X-Forwarded-For: 96.68.149.126
X-Forwarded-Port: 443
X-Forwarded-Proto: https
Connection: keep-alive

Response from CI4

Subscription number:
Activation: No
Error: No parameters sent.

As you can see - the C++ app connects to the CI3 controller, with the Content-Type in the header and returns what I would expect given the parameters I passed in. However, CI4 is not receiving the Content-Type header and tells me that no parameters were passed.

Any thoughts as to why CI4 would be unable to recognize the Content-Type sent by the C++ app?



Solution 1:[1]

It looks like you haven't specified the product architectures correctly. VS2022 is 64-bit, target architecture amd64, and earlier versions are 32-bit, target architecture x86. You need to specify that in the vsixmanifest as described in the docs. In Visual Studio rightclick the manifest in Solution Explorer and do View Code, then overwrite the Installation element with what's below (this is just what the docs say on the link above). It'll show two lines in the manifest designer if you've done it right:

<Installation>
   <InstallationTarget Id="Microsoft.VisualStudio.Community" Version="[15.0,17.0)">
      <ProductArchitecture>x86</ProductArchitecture>
   </InstallationTarget>
   <InstallationTarget Id="Microsoft.VisualStudio.Community" Version="[17.0,18.0)">
      <ProductArchitecture>amd64</ProductArchitecture>
   </InstallationTarget>
</Installation>

This assumes you are just trying to upgrade a template with no code. If you have code it's much, much more complicated than that, which is part of the reason there are so few extensions for VS2022 at the moment. It is all described on those documentation pages though.

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 Rich N