Romain,
I can't be sure, but I think you might be encoding things too much, if that makes sense? Granted, I operate over an open connection, but this is how I do it (FoxPro code, hopefully it makes sense). This is what generating a URL to view a document might look like:
FUNCTION DWViewDocument
LPARAMETERS pcFilecabinetGUID, puDocumentID, plDontRunURL, plUseWindowsAuth
IF (VARTYPE(pcFilecabinetGUID) <> "C") OR EMPTY(ALLTRIM(pcFilecabinetGUID))
* We cannot proceed without a file cabinet GUID.
RETURN ""
ENDIF
* Document ID can be passed in as a numeric value or a string.
IF (VARTYPE(puDocumentID) == "C")
puDocumentID = VAL(puDocumentID)
ENDIF
IF (VARTYPE(puDocumentID) <> "N")
* We cannot proceed without a numeric document ID.
RETURN ""
ENDIF
SET PROCEDURE TO GlobalProc ADDITIVE
LOCAL lcURL
* Establish a base URL with a viewer as the integration type.
lcURL = DWGetBaseIntegrationURL(DW_INTEGRATION_TYPE_VIEWER, plUseWindowsAuth)
* Add on file cabinet GUID.
lcURL = lcURL + "&fc=" + pcFilecabinetGUID
* Add on the document ID.
lcURL = lcURL + "&did=" + ALLTRIM(STR(INT(puDocumentID)))
IF (NOT plDontRunURL)
* Execute the URL.
ExecuteCommand(lcURL)
ENDIF
* The URL used can be returned.
RETURN lcURL
ENDFUNC
Here is what
DWGetBaseIntegrationURL() looks like:
FUNCTION DWGetBaseIntegrationURL
LPARAMETERS pcIntegrationType, plUseWindowsAuth, plDontDisplayOneDoc
IF (VARTYPE(pcIntegrationType) == "C")
pcIntegrationType = UPPER(ALLTRIM(pcIntegrationType))
ELSE
* An empty integration type will make the URL be login-only.
pcIntegrationType = ""
ENDIF
LOCAL lcBaseURL, lcParams
* Start with our integration entry point.
IF plUseWindowsAuth
* Use NTML entry point.
lcBaseURL = DW_INTEGRATION_ENTRY_POINT_NTLM
ELSE
lcBaseURL = DW_INTEGRATION_ENTRY_POINT
ENDIF
lcParams = ""
* Now generate parameters, starting with login credentials (if we are not using a Windows login).
IF (NOT plUseWindowsAuth)
* We are NOT going use Windows authentication, so use login credentials generated here.
lcParams = lcParams + "&lc=" + DWGetURLIntegrationCreds()
ENDIF
* We can set any other defaults here, too.
IF (pcIntegrationType == DW_INTEGRATION_TYPE_RESULTLIST_VIEWER) OR (pcIntegrationType == DW_INTEGRATION_TYPE_HISTORY)
IF (NOT plDontDisplayOneDoc)
lcParams = lcParams + "&displayOneDoc=true"
ENDIF
ENDIF
* Finally, add on the integration type parameter, if we have one.
IF (NOT EMPTY(pcIntegrationType))
lcParams = lcParams + "&p=" + pcIntegrationType
ENDIF
IF (NOT EMPTY(lcParams))
IF (LEFT(lcParams, 1) = "&")
* Do not need the ampersand on the first parameter.
lcParams = SUBSTR(lcParams, 2)
ENDIF
lcBaseURL = lcBaseURL + "?" + lcParams
ENDIF
RETURN lcBaseURL
ENDFUNC
And finally, here is what
DWGetURLIntegrationCreds() looks like:
FUNCTION DWGetURLIntegrationCreds
SET PROCEDURE TO GlobalProc ADDITIVE
LOCAL lcPlainCreds, lcEncodedCreds
* Start with a plain-text credential string. We use a literal "\n" to denote a new-line character
* between username and password, as that is how DocuWare expect the credentials to be encoded.
lcPlainCreds = "User=" + DW_USERNAME_URL_INTEGRATION + "\nPwd=" + DW_PASSWORD_URL_INTEGRATION
* URL encode the plain text into a login credential string.
lcEncodedCreds = UrlTokenEncode(lcPlainCreds)
RETURN lcEncodedCreds
ENDFUNC
The
UrlTokenEncode() function does this (looks the same as yours):
FUNCTION UrlTokenEncode
* This function takes in a string and encodes it the same way System.Web.HttpServerUtility.UrlTokenEncode()
* would to in .NET:
* 1. Use STRCONV to convert the input to Base64.
* 2. Replace "+" with "-" and "/" with "_". Example: Foo+bar/=== becomes Foo-bar_===.
* 3. Replace any number of "=" at the end of the string with an integer denoting how many they were. Example: Foo-bar_=== becomes Foo-bar_3.
LPARAMETERS lcURL
LOCAL lcEncoded, lnNumEqualSigns
* 1. Convert string to Base64.
lcEncoded = STRCONV(lcURL, 13)
* 2. Replace certain characters with others.
lcEncoded = CHRTRAN(lcEncoded, "+/", "-_")
* 3. See how many "=" are at the end of the encoded string and convert to digit.
lnNumEqualSigns = LEN(lcEncoded) - LEN(RTRIM(lcEncoded, 1, "="))
lcEncoded = LEFT(lcEncoded, LEN(lcEncoded) - lnNumEqualSigns)
lcEncoded = lcEncoded + ALLTRIM(STR(lnNumEqualSigns))
RETURN lcEncoded
ENDFUNC
After all this, the URL is sent as-is -- no further encryption. User credentials and the query parameter are Url encoded, but that is it.
Maybe that won't work if you are using a secure connection, but on my system what I generate matches the URL Integrator, and the URLs work to do things like view documents. Your user credentials look correct, so it must be something with encrypting/encoding.
Good luck,
Joe Kaufman