Hello, I would like to make an HTTP Request in FlexSim. Therefore I have to submit an username and a passwort to the Website. How does this work?
Hello, I would like to make an HTTP Request in FlexSim. Therefore I have to submit an username and a passwort to the Website. How does this work?
Hi @Max R4, was Ben Wilson's answer helpful? If so, please click the "Accept" button at the bottom of their answer. Or if you still have questions, add a comment and we'll continue the conversation.
If we haven't heard back from you within 3 business days we'll auto-accept an answer, but you can always unaccept and comment back to reopen your question.
Often username and password authentication tokens are sent in the HTTP request header. Check out this Q&A for some background on using the Http.Request headers property.
You may consider using a normal browser to see what the proper HTTP authentication headers should look like for authenticating with your remote service. Use your browser's dev tools (F12) and watch the network tab to examine an HTTP authenticated request to your service endpoint. Note how the headers are formatted and mimic that formatting in the hand-coded Http.Request in FlexSim.
Http.Request request; request= Http.Request("https://xyz.com"); request.headers = "Authorization: username:password"; Http.Response response = request.sendAndWait( print (response.statusCode);
We just used this logic to check the status code, but we always get the return value 0 for the statuscode. The password in the development tool is shown in base-64 format. Rechanging the username:password with the decoded password doesn´t solve the problem. I don´t have any idea how to continue.
Hi @Max R4,
It's tough to know exactly what to suggest when we know nothing about the API you're contacting, but I found a public example that may be able to help you in your circumstance.
This AnswerHub community has an API, and the docs for it include a nice, testable example feature. Check out their documentation for the Retrieve User Information endpoint. In the sidebar you'll see a box you can use to test against sample data. This allows you to get experience using their API and helps you know what to expect when you call their endpoints:
As you type the username (answerhub) and password (test123) into the form fields, the data for the Authorization header populates (base64-encoded). You then have all the information you need to make that request yourself from different platforms. In FlexSim, you would translate the above cURL request (see image) into FlexSim's Http.Request API like this:
Http.Request r; r.method = Http.Method.Get; r.useSSL = 1; r.port = 443; r.host = "apidocs.cloud.answerhub.com"; r.path = "services/v2/user/7.json"; r.headers = "Accept: application/json\r\nAuthorization: Basic YW5zd2VyaHViOnRlc3QxMjM=\r\nContent-type: application/json"; r.successCallback = model.find("/Tools/success"); r.failCallback = model.find("Tools/fail"); r.send();
Notice the headers are an "\r\n" delimited string.
I've put this example code into the attached sample model, along with success and fail callbacks which dump all Http.Response data to the output console. Just execute the open script window pinned to the bottom (nested with the compiler console) to test this code.
Hopefully this will help you to make progress with the API you're contacting. There are some APIs where the authentication tokens are passed through the data parameter (or even the URL), rather than headers (Trello's API is one example). Each API can be a bit different, so there isn't a one-size-fits-all solution that I can tell you will definitely work for the server you're trying to contact.
Hopefully you have access to the documentation for the service you're trying to access and you'll be able to figure it out. Good luck!
Hi @Ben Wilson
Could you please reshare this model, I was unable to download https://answers.flexsim.com/storage/attachments/58072-answersq-127548-httpauthtest-answersfsm.jpg
If you see this again, you can just rightclick the link and choose 'save link as'. The issue is that the browser is trying to view the jpg.
16 People are following this question.
FlexSim can help you understand and improve any system or process. Transform your existing data into accurate predictions.
FlexSim is a fully 3D simulation software environment. FlexSim can be used to simulate any process in any industry.
FlexSim®, FlexSim Healthcare™, Problem Solved.®, the FlexSim logo, the FlexSim X-mark, and the FlexSim Healthcare logo with stylized Caduceus mark are trademarks of FlexSim Software Products, Inc. All rights reserved.
Privacy | Do not sell or share my personal information | Cookie preferences | Report noncompliance | Terms of use | Legal | © Autodesk Inc. All rights reserved