I have a code which does a POST to a URL. The code uses setFixedLengthStreamingMode since it knows the length of POST in advance.
I am having a situation where in some cases the URL could be redirected to something else and since streaming mode is enabled; its not able to follow redirect.
Is there any way to do a check before actually posting the data to see if URL is getting redirected or not? Or am I thinking in wrong direction?
I have a code which does a POST to a URL. The code uses
Share
In general, no, there isn’t. In a normal web use case though after a POST request done from a submit form you should always get a redirect as per best practices, but this is far from guaranteed. For example, it can do a request if data is similar, and not do it if it is something else. It can always fail with an error.
For some limited use cases there might be some logic that is always followed, but that is case-by-case thing then.
From documentation:
So while the redirect will not be handled automatically, and even though you cannot really check for redirect beforehand, what you can do is that you can catch the exception and perform steps yourself based on that.