DSRestConnection to a user and password protected server on https on android
I'm writing clients to a user and password protected server that's using datasnap ServerMethods on port 443 (https).
Everything is working nicely on Windows and IOS, but I think something is wrong on Android, I'm keep getting exception "HTTP/1.1 401 Unauthorized", I've checked Password/Username and "Test Connection" on the DSRestConnection component gives no errors.
Using the web-browser on the android unit to manually enter the url also works without errors.
The webserver used is a Windows IIS 7.5 with basic authentication enabled. Switching off Basic Authentication and allowing Anonymous Authentication solves the problem on android, but that's not really a good option.
-
Accepted Answer
0I did some more testing and it look's like a serious problem.
Authentication doesn't work on Android even if:
- Using standard http on port 80
- Trying other types of Authentication standards on IIS like Digest Authentication
- Using TNetHTTPClient component with proper "OnAuthEvent" instead of TDSRestConnection component
Also, it's not 100% on an iOS Device, the first attempt always causes a "HTTP/1.1 403 forbidden" exception, following attempts works without any errors. I think this error could be related to this reported bug https://quality.embarcadero.com/browse/RSP-11247 but with my limited C++ knowledge I don't know how to add custom headers to the TNetHTTPClient as suggested in the comments.
-
Accepted Answer
0Hi Pawel!
It's C++ Builder 10.2 Enterprise edition. The Android device (Samsung Galaxy S6 have version 7.0 installed), Android SDK is 25.2.5
On Android I was forced to call the DataSnap request on a separate thread, as android doesn't seem to like making network requests from the main thread.
Another annoying "feature" is that after adding DataSnap features the app crashes while being idle after about 15 minutes or so. Doesn't feel very stable.
void __fastcall TMainForm::ThreadFunction(void) { try { valid = Conn->ValidID(ID); } catch (const Exception & e) { ErrorMsg=e.Message; } } void __fastcall TMainForm::ValidateID(void) { ErrorMsg=""; Conn = new TServerMethods1Client(DSRestConnection1); TThread * RThread = TThread::CreateAnonymousThread([]() { MainForm->ThreadFunction(); } ); RThread->Start(); while (!RThread->Finished) Application->ProcessMessages();
-
Accepted Answer
0Hi Andreas,
Do you use Delphi or C++Builder? Which version? Which Android version do you use?
Paweł