AJAX request in LAN (MSI Afterburner Remote Server)?

Get help using Construct 2

Post » Thu Jul 20, 2017 3:52 pm

Hi, I need your help. :(

I try to make a small personal smartphone app, that shows me my pc stats like cpu load and such.

I use MSI Afterburner and MSI Remote Server for this. The app is working so far in preview, but only in NWjs, in Chrome or on my smartphone with lan preview, the AJAX request fails. I think the problem is, that i dont have "Access-Control-Allow-Origin: *" in php header. But MSI Remote server has no php files.

Has somebody an idea, how i can get this to work?
B
11
S
4
G
5
Posts: 74
Reputation: 3,435

Post » Thu Jul 20, 2017 5:05 pm

I'm not sure how MSI Remote Server works, but if it runs on Apache then you can use .htaccess file with the following content:

Code: Select all
<IfModule mod_headers.c>
Header set Access-Control-Allow-Origin "*"
</IfModule>
ImageImageImage
B
27
S
16
G
74
Posts: 977
Reputation: 41,673

Post » Thu Jul 20, 2017 6:01 pm

@BackendFreak i placed the .htaccess file in the directory of msi remote server, but still nothing.

Why does it work with nwjs but not with any other browser or on my smartphone?
If i open the ip directly in browser, i'll get the xml output from the server, even on my phone, but not in construct.

This is how the code looks like:

Image

i upload the .capx file, MSI Afterburner and the MSI Remote Server, if somebody likes to help me with my problem.

.capx
MSI Afterburner
MSI Afterburner Remote Server
B
11
S
4
G
5
Posts: 74
Reputation: 3,435

Post » Thu Jul 20, 2017 7:42 pm

Is there any error message in the browser console when it fails?
ImageImageImage
B
27
S
16
G
74
Posts: 977
Reputation: 41,673

Post » Thu Jul 20, 2017 8:34 pm

chrome console gave me this, so you were right with your assumption:
Code: Select all
XMLHttpRequest cannot load http://192.168.0.50:82/mahm. No 'Access-Control-Allow-Origin' header is present on the requested resource. Origin 'http://192.168.0.50' is therefore not allowed access. The response had HTTP status code 401.

The question is, why is nwjs working and chrome not, and how do i grant construct access for the ajax call?
B
11
S
4
G
5
Posts: 74
Reputation: 3,435

Post » Fri Jul 21, 2017 12:35 am

Hmm it could be that NW.js is treated as the same host (same IP) as the one you're trying to connect to, while Chrome preview starts it's own "server" and has it's own IP.

I am not sure how NW.js preview is treated from this perspective. It could also be related to some Chromium args like "--disable-security" or something.

And It's possible that AJAX works differently for NWjs. It may actually search for the file locally.

Can you check what will something like this log to the console both in the Browser and NWjs?
Image

It's interresting that it works in NWjs. I'm curious what's behind it. @Ashley is this maybe something you would know from the top of your head?
ImageImageImage
B
27
S
16
G
74
Posts: 977
Reputation: 41,673

Post » Fri Jul 21, 2017 10:08 am

Most likely NW.js just disables security, which is probably not a great idea and sets up compatibility traps like this. You should configure the server correctly anyway. If you're not sure how to configure the server it would be best to contact support for MSI or whoever develops the server.
Scirra Founder
B
395
S
232
G
88
Posts: 24,371
Reputation: 193,762

Post » Fri Jul 21, 2017 12:50 pm

Kitsune42k wrote:The question is, why is nwjs working and chrome not, and how do i grant construct access for the ajax call?

This question is very similar to this topic. Grigrizljac gave me a very helpful answer, hope it helps you too.
Kitsune42k wrote:I try to make a small personal smartphone app

However, if you plan to export to Android, it should work fine in the exported version.
B
20
S
6
Posts: 143
Reputation: 1,666

Post » Fri Jul 21, 2017 3:21 pm

@BackendFreak The log in Chrome and NWjs prints the same output for Browser.URL and Browser.Domain:
Code: Select all
http://192.168.0.50/
192.168.0.50



@Ashley That are the remote server files:
Image

That is the config file in the app dir, it is primarily for setting up the the real config file in appdata:
Code: Select all
<?xml version="1.0"?>
<configuration>
<configSections>
    <sectionGroup name="applicationSettings" type="System.Configuration.ApplicationSettingsGroup, System, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" >
        <section name="MSIAfterburnerRemoteServer.Properties.MSIAfterburnerRemoteServer" type="System.Configuration.ClientSettingsSection, System, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" requirePermission="false" />
    </sectionGroup>
    <sectionGroup name="userSettings" type="System.Configuration.UserSettingsGroup, System, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" >
        <section name="MSIAfterburnerRemoteServer.Properties.Settings" type="System.Configuration.ClientSettingsSection, System, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" allowExeDefinition="MachineToLocalUser" requirePermission="false" />
    </sectionGroup>
</configSections>
<startup><supportedRuntime version="v2.0.50727"/><supportedRuntime version="v4.0"/></startup>
    <userSettings>
        <MSIAfterburnerRemoteServer.Properties.Settings>
            <setting name="Port" serializeAs="String">
                <value>82</value>
            </setting>
            <setting name="IPAddress" serializeAs="String">
                <value>*</value>
            </setting>
            <setting name="Key" serializeAs="String">
                <value>17cc95b4017d496f82</value>
            </setting>
            <setting name="MonitorOnly" serializeAs="String">
                <value>False</value>
            </setting>
            <setting name="NormalizeXMLResponse" serializeAs="String">
                <value>True</value>
            </setting>
            <setting name="UseRealtimeOCValues" serializeAs="String">
                <value>False</value>
            </setting>
        </MSIAfterburnerRemoteServer.Properties.Settings>
    </userSettings>
</configuration>

And that is the config of the remote server in appdata:
Code: Select all
<?xml version="1.0" encoding="utf-8"?>
<configuration>
    <userSettings>
        <MSIAfterburnerRemoteServer.Properties.Settings>
            <setting name="Key" serializeAs="String">
                <value>b3fe4ee9c3c91bd28ad1b8e144498764</value>
            </setting>
            <setting name="MonitorOnly" serializeAs="String">
                <value>True</value>
            </setting>
            <setting name="NormalizeXMLResponse" serializeAs="String">
                <value>True</value>
            </setting>
            <setting name="UseRealtimeOCValues" serializeAs="String">
                <value>False</value>
            </setting>
        </MSIAfterburnerRemoteServer.Properties.Settings>
    </userSettings>
</configuration>

I see no possibility to configure the server :?



@ChesVCF Thanks for sharing the topic with me, it was exactly that. I disabled the the security in chrome with this command:
Code: Select all
chrome.exe --disable-web-security --user-data-dir
Now the AJAX request works.

I will try to export my project and test it on my smartphone. I hope it will work than ;)
B
11
S
4
G
5
Posts: 74
Reputation: 3,435

Post » Fri Jul 21, 2017 3:38 pm

You really, really should not go around turning off web security in Chrome. It opens up gigantic security holes. I would guess it enables any web page you visit to hijack your Facebook account or any other account you're signed in to, and that's just for starters. You should set up the correct HTTP headers. If you don't know how to, contact the server developer for support, or try a different web server that's easier to set up (both nginx and caddy seem pretty straightforward).
Scirra Founder
B
395
S
232
G
88
Posts: 24,371
Reputation: 193,762

Next

Return to How do I....?

Who is online

Users browsing this forum: David181, OBLIVION and 55 guests