NETWORK_CONNECTTIMEOUT with SSL
-
Hello,
Trying to extend the network connect timeout, following this example:
// This example retrieve the result from a POST and print it. maxon::Url theServer { "http://localhost:8080"_s }; // Prepares the data that will be post maxon::String postData = "foo=bar&bin=go"_s; theServer.Set(maxon::URLFLAGS::HTTP_POSTMETHOD, maxon::HTTPMETHOD::POST) iferr_return; theServer.Set(maxon::URLFLAGS::HTTP_POSTDATA, maxon::CString(postData, maxon::StringEncodings::Utf8())) iferr_return; maxon::BaseArray<maxon::Char> memReq; // Retrieves the answer and read it to memory iferr (maxon::FileUtilities::ReadFileToMemory(theServer, memReq)) DiagnosticOutput("@", err); // Prints the answer from server ApplicationOutput("answer @", memReq); // Prints the answer as a string maxon::String result(memReq); ApplicationOutput("result @", result);Using the following works well on http localHost, but does not work with SSL (web https):
theServer.Set(maxon::URLFLAGS::NETWORK_CONNECTTIMEOUT, maxon::Milliseconds(15 * 1000)) iferr_return; // allow 15 seconds before timeout theServer.Set(maxon::URLFLAGS::NETWORK_SESSIONTIMEOUT, maxon::Milliseconds(15 * 1000)) iferr_return;How can we force the timeout extension when using SSL ? Currently it defaults to around 10 seconds. Also, for SSL, do we need to do anything other than setting the flags ?
Thanks.
-
Hey @Rox,
Thank you for reaching out to us. Please provide a concrete executable code example as to what exactly does not work with SSL. I understand that you have put effort into make yourself understood, but in the current form it is very ambiguous what it not working for you.
HTTPS methods surely work, we use them heavily internally, in all variants such as GET, POST, DELETE, etc. I looked at our code base and did not find an exact match for POSTing towards an HTTPs endpoint with a custom timeout, but found one for DELETEing.
You can connect to an https URL without any extra steps. I am not quite sure what you would consider "setting the flags" in your code. Depending on the endpoint you want to reach, you might have to configure your headers though.
UrlInterfaceis not a web framework which would automate these things for you.Here is some slightly obfuscated production code for posting towards an (https) endpoint:
Bool DoRequestPost( const maxon::String& endpoint, const maxon::CString& postData, Bool isFile = false, maxon::DataDictionary* responseAsDict = nullptr, maxon::BaseArray<maxon::DataDictionary>* responseAsArray = nullptr) { if (isFile) { additionalHeader.Set("Content-Type"_s, FormatString("multipart/form-data; boundary=@"_s, boundary)) iferr_cannot_fail("Cannot set content type"_s); additionalHeader.Set("Some-Token"_s, "no-check"_s) iferr_cannot_fail("Cannot set Some-Token"_s); } else { additionalHeader.Set("Content-Type"_s, "application/json"_s) iferr_cannot_fail("Cannot set content-type"_s); additionalHeader.Set("Accept"_s, "application/json"_s) iferr_cannot_fail("Cannot set accept datatype"_s); } url = maxon::Url(); url.Set(maxon::URLFLAGS::HTTP_ADDITIONAL_REQUEST_HEADER, additionalHeader) iferr_cannot_fail("Cannot set additional headers"_s); url.Set(maxon::URLFLAGS::HTTP_POSTMETHOD, maxon::HTTPMETHOD::POST) iferr_cannot_fail("Cannot set httpmethod"_s); url.Set(maxon::URLFLAGS::HTTP_POSTDATA, postData) iferr_cannot_fail("Cannot set post data"_s); url.Set(maxon::URLFLAGS::HTTP_NO_PROXY_CACHING, true) iferr_cannot_fail("Cannot set NOPROXY"); return DoRequest(endpoint, responseAsDict, responseAsArray); }Cheers,
Ferdinand -
Thank you for the snippet Ferdinand.
Timeout do still happen, but less frequently now. -
Timeouts should not happen unless the endpoint is indeed timing out. But as I said, I cannot help you unless you give me compilable code (i.e., a little self contained function) with which I can reproduce your claims. If possible, please also share your endpoint as it obviously plays a major role in this problem.
-
For now I am good. If I need further help, I will send the endpoint and function by email.