question

Yue Y avatar image
0 Likes"
Yue Y asked Phil BoBo commented

Is applicationcommand("sendhttprequest") secure?

After running the example provided here https://answers.flexsim.com/questions/21092/web-communication-within-flexsim.html It seems that applicationcommand("sendhttprequest", verb, server, object, data, silent, result) send a https request under the hood. Is there a way to toggle this feature in the case that the server I want to talk to doesn't support https?

FlexSim 19.1.0
httphttpsweb
5 |100000

Up to 12 attachments (including images) can be used with a maximum of 23.8 MiB each and 47.7 MiB total.

Phil BoBo avatar image
2 Likes"
Phil BoBo answered Phil BoBo commented

applicationcommand("sendhttprequest") calls the WinHttpConnect function, passing INTERNET_DEFAULT_PORT for the port number.

This will use port 80 for HTTP requests and port 443 for HTTPS requests.

If the server you want to talk to doesn't support https, then it will use http.

Also, you cannot change the port numbers with that application command. If you want more control, you can use C++ with the DLL Maker or the Module SDK instead of an application command.

· 4
5 |100000

Up to 12 attachments (including images) can be used with a maximum of 23.8 MiB each and 47.7 MiB total.

Yue Y avatar image Yue Y commented ·

How does applicationcommand know if it's a http requests or https request?

since in the command applicationcommand("sendhttprequest", verb, server, object, data, silent, result) we can't specify protocol?

0 Likes 0 ·
Phil BoBo avatar image Phil BoBo ♦♦ Yue Y commented ·

WinHTTP handles it while trying to open a connection with the specified server.

See SSL in WinHTTP.

EDIT: on further investigation, it looks like you might need to pass the flag WINHTTP_FLAG_SECURE to WinHttpOpenRequest in order to tell it to use SSL.

applicationcommand("sendhttprequest") isn't passing that flag, so it might not be using HTTPS, unless something else can also enable it, such as specifying "https:" in the URL or a server that only accepts https requests.

Again, if you want to have more control, use C++ with the DLL Maker or the Module SDK.

0 Likes 0 ·
Yue Y avatar image Yue Y Phil BoBo ♦♦ commented ·

Since we can't change the port number with applicationcommand("sendhttprequest"), if we send a request to "localhost", does it mean the request will be sent to "localhost:80"?

0 Likes 0 ·
Show more comments
Boris V2 avatar image
0 Likes"
Boris V2 answered Phil BoBo commented

The command "sendhttprerquest " works fine with HTTP web sites, but I have an error message when I try to send a request to HTTPS, see attached model. Have you got an idea to solve this issue? Thanks

testRecupJson01.fsm


1607625471164.png (77.1 KiB)
testrecupjson01.fsm (28.7 KiB)
· 3
5 |100000

Up to 12 attachments (including images) can be used with a maximum of 23.8 MiB each and 47.7 MiB total.

Phil BoBo avatar image Phil BoBo ♦♦ commented ·

Don't use that application command anymore. Use the HTTP FlexScript API.

Here's an example script like your model using FlexSim 21.0's FlexScript APIs such as HTTP and JSON:

Http.Request request;
request.method = Http.Method.Get;
request.host = "api.nasa.gov";
request.path = "/planetary/apod";
request.data = "api_key=DEMO_KEY";
request.useSSL = 1;
Http.Response response = request.sendAndWait();
string json = response.value;
Map map = JSON.parse(json);
return map;
1 Like 1 ·
Boris V2 avatar image Boris V2 Phil BoBo ♦♦ commented ·

Thanks for your answer witch give me hope for my next developpement, but I have developed all my model + webserver in 20.0.9, is there any other option?

0 Likes 0 ·
Phil BoBo avatar image Phil BoBo ♦♦ Boris V2 commented ·
1 Like 1 ·