I am calling some endpoints using system.net.httppost method.
It works for valid URLs.
I want to check if the URL is valid and available before calling the post method.
Is there a way to validate a URL in ignition?
Some googling around shows that I should install "requests" module for this and use Head method, check status codes to determine a valid URL.
I am wondering if Ignition provides any inbuilt method /way to do this.
I like to avoid installing extra modules if possible.
Please let me know.
What version of Ignition are you using?
system.net.httpClient supports the HTTP HEAD method.
It exists in 8.0 as well.
I have to ask though... what's the point of making a whole extra HTTP request that might fail? Why not just make the POST? What if the server doesn't implement HEAD?
That's a very good point.
Honestly I don't know what is the best way to validate a url to make sure it is available.
We are trying to know whether the API is available. In case not(server down or communication issue), then update the transaction status accordingly, the transaction that we are trying to post.
If you could suggest good ways to achieve this, that would be awesome.
Just call it. It will fail if it's not available. You don't need an extra call before it that also might fail for totally unrelated reasons.
If you are using httpClient, there is a response function isGood() in the documentation. We basically will use that as our initial error handling and respond as needed if the response fails or returns an error.
That is what I am doing now.
I am using system.net.httppost method which does not return status code.
Is there a way to get the status codes in the response?
I am using system.net.httppost method
@Kevin.Herron So, I used httpClient. It works fine.
But I am facing a situation mentioned below-
When i call the function which is using httpClient to invoke the endpoint from Script Console, it works absolutely fine. I get what i expect.
But when i call the same function from a gateway timer script, a get a 403 error.
I am not sure why this could happen.
I am using Basic Authentication passing username and password.
Could you please help me on this?
The only difference is that when you execute in the script console the HTTP call is made from the computer running in the Designer, and when you execute in a gateway timer script the call is made from the server running the Ignition Gateway.
Unless you've made a coding mistake that results in the wrong credentials being used, then you need to look external to Ignition - OS security, a proxy, a firewall, or some other network appliance interfering with the call. Work with your IT team.