After converting my project over to Ionic 3 using httpclient, I’m now running into the problem where my .Net api endpoint is running twice on post calls. This only happens the first time I hit a given endpoint. Subsequent calls only cause it to fire once.
Seeing as I’m specifying json headers I’m assuming an Options preflight request is the culprit, but I’m confused why the endpoint is processing both requests. Shouldn’t the preflight just confirm the post can be made and not actually deliver a payload to the endpoint? Are subsequent calls using cached info that alleviates future Options requests when hitting the same endpoint?
My logic inside the clients post subscribe is only getting hit once with a single response but my server logic is running twice, causing duplicate records being created. Is there a setting in IIS to configure or does Ionic posts using httpclient require more configuration? I’m assuming it’s related to httpclient as no other changes were made to the logic when converting to Ionic 3.
Did you remote debug the problem on the device already?
Follow these instructions here to debug the problem in Safari dev tools: https://ionic.zone/debug/remote-debug-your-app#ios
Follow these instructions here to debug the problem in Chrome dev tools: https://ionic.zone/debug/remote-debug-your-app#android
Look at the network tabs for the requests - and take note of the method used. POST/OPTIONS? Does your server handle the OPTIONS correctly and not process the actual request?
I am able to watch the network and noticed I’m sending one OPTIONS and one POST request from the client. The API endpoint in turn appears to get hit 2 (or more) times for that request and processes it like three individual requests. Then any subsequent requests I see one OPTIONS and one POST request that gets processed once on the API endpoint. Why are these requests suddenly getting processed twice since moving to Ionic 3?
I’m assuming something on the browser is being cached after the first call that keeps secondary requests from causing the API to fire multiple times. Seeing as the only thing that has changed in my project is the use of the new httpclient makes me think it’s the culprit.