2017-07-20 67 views
0

我想從.NET以外的地方使用DocuWare Platform SDK(它工作的很好)。 DocuWare論壇一直沒有幫助,並且支持票據被告知我們沒有購買特定的SDK許可證支持。因此,我使用「InternetExplorer.Application」COM對象來自動登錄到DocuWare登錄頁面,這樣我就可以進一步使用該會話進行基於cookie的身份驗證(無法獲取任何其他內容以作爲工作目標就像cookie的持久性一樣)。Internet Explorer自動化 - 無法提交表單

我可以調出網頁並填寫字段,但無論如何我都無法提交表單。下面是代碼(Visual FoxPro中):

lcURL = "https://docuware-online.com/DocuWare/Platform/Account/Logon?returnUrl=/DocuWare/Platform/Home/XSL" 
loIE = CREATEOBJECT("InternetExplorer.Application") 
loIE.Navigate(lcURL) 
WaitForIE(loIE) 
loDocument = loIE.Document 
loDocument.getElementById("UserName").Value = "user" 
loDocument.getElementById("Password").Value = "password" 
loDocument.getElementById("Organization").Value = "My Organization" 
loDocument.getElementById("RememberMe").Checked = .T. 
loInputs = loDocument.getElementsByTagName("input") 
FOR EACH loInput IN loInputs 
    IF UPPER(ALLTRIM(loInput.Value)) == "LOG ON" 
     loInput.Click() 
    ENDIF 
ENDFOR 
WaitForIE(loIE) 
loIE.Visible = .T. 

(WaitForIE是簡單地循環,直到IE實例的readyState的一個程序4.它工作正常。)

我知道代碼到達loInput.Click()線,因爲我已經完成了它。所以這不是關於一個元素沒有被發現,據我所知。

對於提交,我也試過loDocument.Forms(0).Submit(),但那也行不通。當我準備登錄按鈕時,我也試過loInput.Form.Submit()。仍然沒有運氣。

正如我所說的,導航和填寫表單元素工作正常。我只是無法提交表單。

我正在使用Internet Explorer 11.這種事情簡直不再可能與最新版本的IE?還有什麼其他的自動化對象可以使用,並讓Cookie保持對我的會話持久性?我不知道SDK的.NET實現如何工作,因爲它將所有內容都包含在我無法深入研究的ServiceConnection對象中。

任何人都可以訪問有問題的網頁,所以如果任何人都可以得到提交的東西,我會有興趣聽到如何!

由於提前,

sutekh137

UPDATE:

好了,我錯過了已張貼在其他地方的答案,所以感謝誰被發現之前的解決方案回答了這個主題的人!

順便說一句,我不再需要IE自動化。我終於想出瞭如何使用基本的POST登錄到DocuWare服務器,並且它似乎保持cookie身份驗證持久。此外,DocuWare Logon資源可以採用returnUrl參數,讓參數在一次調用中執行簡單的GET操作。對於需要發送數據的任何其他請求(如POST),可以再次簡單地使用XMLHTTP請求對象,並且它似乎仍保持通過身份驗證。

綜上所述,代碼使用.NET的DocuWare平臺SDK外面看起來是這樣的:

#DEFINE DW_ORG      "<org name>" 
#DEFINE DW_ORG_ID     "<ord ID>" 
#DEFINE DW_SERVER     "<DocuWare server name/IP>" 
#DEFINE DW_USERNAME     "username" 
#DEFINE DW_PASSWORD     "password" 
#DEFINE DW_PROTOCOL     "http" 
#DEFINE DW_INTEGRATION_ENTRY_POINT DW_PROTOCOL + "://" + DW_SERVER + "/DocuWare/Platform/WebClient/" + DW_ORG_ID + "/Integration" 
#DEFINE DW_SDK_ENTRY_POINT   DW_PROTOCOL + "://" + DW_SERVER + "/DocuWare/Platform" 

FUNCTION DWSDKSendAndReturnRequest 
    LPARAMETERS pcSDKResource, pcRequestType, pcRequestData, plDontUseWindowsAuth, pcError 
    IF (VARTYPE(pcSDKResource) == "C") AND (NOT EMPTY(ALLTRIM(pcSDKResource))) 
     pcSDKResource = ALLTRIM(pcSDKResource) 
    ELSE 
     * If there is no resource to run, then we cannot proceed. 
     pcError = "No DocuWare SDK resource provided." 
     RETURN .NULL. 
    ENDIF 
    IF (VARTYPE(pcRequestType) == "C") AND (NOT EMPTY(ALLTRIM(pcRequestType))) 
     pcRequestType = UPPER(ALLTRIM(pcRequestType)) 
    ELSE 
     * Default request type is a "GET". 
     pcRequestType = "GET" 
    ENDIF 
    IF (VARTYPE(pcRequestData) == "C") AND (NOT EMPTY(ALLTRIM(pcRequestData))) 
     pcRequestData = UPPER(ALLTRIM(pcRequestData)) 
    ELSE 
     * Default data to send in a request is just an empty string. 
     pcRequestData = "" 
    ENDIF 
    * Our output variable for any error text should start out empty. 
    pcError = "" 
    * We can tidy up the resource parameter if the user has taken some shortcuts with what they passed in... 
    IF (LEFT(pcSDKResource, 1) <> "/") 
     * SDK Resource should always start with a slash. 
     pcSDKResource = "/" + pcSDKResource 
    ENDIF 
    IF (UPPER(LEFT(pcSDKResource, 18)) <> "/DOCUWARE/PLATFORM") 
     * Resource should always start with proper DocuWare platform location. 
     pcSDKResource = "/DocuWare/Platform" + pcSDKResource 
    ENDIF 
    LOCAL llAllInOneRequest, lcLogonVerb, loRequest, lcLoginURL, lcRequestURL, loErr 
    IF plDontUseWindowsAuth 
     lcLogonVerb = "Logon" 
    ELSE 
     lcLogonVerb = "LogonNTLM" 
    ENDIF 
    lcLoginData = "Organization=" + DW_ORG + "&UserName=" + DW_USERNAME + "&Password=" + DW_PASSWORD 
    lcLoginURL = DW_SDK_ENTRY_POINT + "/Account/" + lcLogonVerb 
    IF (pcRequestType == "GET") 
     * For a GET, we can call the resource request right inline wit hthe authentication request 
     * by utilizing the the "returnUrl" parameter in our login POST. 
     llAllInOneRequest = .T. 
     lcLoginURL = lcLoginURL + "?returnUrl=" + pcSDKResource 
    ELSE 
     llAllInOneRequest = .F. 
    ENDIF 
    TRY 
     loRequest = CREATEOBJECT("MSXML2.ServerXMLHTTP") 
     loRequest.Open("POST", lcLoginURL) 
     * The following line is critical for successful authentication via the POST. 
     loRequest.setRequestHeader("Content-Type", "application/x-www-form-urlencoded") 
     loRequest.Send(lcLoginData) 
     * If our request type is NOT a "GET", then we should run the resource request 
     * as a second request because our Logon call was not "all in one". 
     IF (NOT llAllInOneRequest) 
      * We need to make our resource name into a full URL. 
      lcRequestURL = DW_PROTOCOL + "://" + DW_SERVER + pcSDKResource 
      loRequest.Open(pcRequestType, lcRequestURL)  
      loRequest.Send(pcRequestData) 
     ENDIF 
    CATCH TO loErr 
     SET CONSOLE OFF 
     pcError = loErr.Message 
     loRequest = .NULL. 
    ENDTRY 
    RETURN loRequest 
ENDFUNC 

(很抱歉在FoxPro我的樣本之中,但它是很容易閱讀,看看到底是怎麼回事)

希望這有助於任何人試圖使用DocuWare提供的.NET封裝之外的DocuWare平臺SDK。

回答

1

查看張貼在:
FoxPro Internet Explorer COM Automation: Clicks not working in IE 10 and Later?

最特別的是公認的答案(用複選標記)。

+0

非常感謝。在我所有的搜索中,我沒有在搜索條件中添加「foxpro」,因爲我認爲沒有人再與Foxpro混淆。但事實證明,這是一個Foxpro問題,具體而言!通過添加一個虛假參數來點擊()和/或提交()調用,自動化運行效果很好。非常感激! – sutekh137