What a challenge. I tried to call a REST webservice from a ASPX website with my springboot application. The REST service only supports POST requests (I do not understand why, but this is maybe another story).
When I use the default spring RestTemplate to invoke a REST request I always get error 404 or 401 from the REST service. Doing the same with Chrome or IE the request works without any problem. So what is the difference?
It seems our browsers doing more than the spring RestTemplate. They are doing some roundtrips to handle NTLM authentication. The question is now: How can I do the same with spring?
The answer is fairly simple but I do not have found any official documentation about this. Simple do something like the following:
RestTemplate template = new RestTemplate();
// !!! We require this request to work with NTLMv2
template.headForHeaders("https://mydomain/theAspxService/");
The headForHeaders() method do the NTLMv2 authentication stuff. Any further requests using then the Ntlm auth header to talk with the ASPX service and they can then authenticate and invoke the requests.
For sure, you need general able to authenticate to the service. So check first with your browser if the requests really working for your windows user.
Kommentar verfassen