"winhttp.winhttprequest.5.1"을 통한 Mantis BT 수출 요청
-
13-09-2019 - |
문제
상사는 저에게 Corp의 Mantis Bugs 데이터베이스를 Excel로 내보내라고 요청했지만 SQL 서버에 액세스 할 수는 없으며 프로세스를 자동화해야합니다.
내가 사용할 수있는 유일한 것은 Excel입니다 (ODBC 없음, 수동 수출 없음).
그래서 나는 이것을했다 :
Dim webClient As Object
Dim i As Long, vFF As Long, oResp() As Byte
Dim vLocalFile As String
Dim username As String, password As String
username = "blahblah"
password = "blahblah"
Set webClient = CreateObject("WinHttp.WinHttpRequest.5.1")
// Opening the connection to the application with a POST, containing user, password, and "permanent login" checked
webClient.Open "POST", "http://10.202.157.40/mantisbt-1.1.6/login.php", False
webClient.setRequestHeader "Content-Type", "application/x-www-form-urlencoded"
webClient.send ("username=" & username & "&password=" & password & "&perm_login=on")
// Now I set the "project" to "All Projects" (as I want the view to display our 2200 bugs)
webClient.Open "POST", "http://10.202.157.40/mantisbt-1.1.6/set_project.php", False
webClient.setRequestHeader "Content-Type", "application/x-www-form-urlencoded"
webClient.send ("project_id=0")
// The problem is, the last query displays 624 bugs instead of 2200, but I noticed when I click on "Advanced Filters" it successfully show the 2200 bugs (tested under a web browser AND Excel : the ResponseText shows them)
webClient.Open "GET", "http://10.202.157.40/mantisbt-1.1.6/view_all_set.php?type=6&view_type=advanced", False
webClient.send
// And NOW I can download the CSV file... (and that's where something is wrong *)
webClient.Open "GET", "http://10.202.157.40/mantisbt-1.1.6/csv_export.php", False
webClient.send
oResp = webClient.responseBody
// Creating a file and then filling it...
vFF = FreeFile
vLocalFile = "_mantis_export.csv"
If Dir(vLocalFile) <> "" Then Kill vLocalFile
Open vLocalFile For Binary As #vFF
Put #vFF, , oResp
Close #vFF
// Freeing memory
Set webClient = Nothing
(* : cf 코드) 이전 줄에, responsext는 "2200 버그"를 보여 주었으므로 마지막 쿼리 (csv_export.php)까지 모든 것이 괜찮 았습니다. 브라우저를 통해 호출 될 때 스크립트는 호출 된 페이지와 정확히 동일하게 표시됩니다 (페이지에 2 개의 버그가 표시되면 CSV에는 2 개의 버그가 포함되어 있음). IE / Firefox에 2200 개의 버그가 표시되면 CSV는 2200 개의 버그를 제공합니다. 그러나 excel에서는 responceetext에 2200 개의 버그가 표시 되더라도 CSV는 624 개의 버그를 가져옵니다 ... 마치 "고급 필터"페이지를 호출하지 않은 것처럼 :(
나는 누군가가 나를 이해하고 도울 수 있기를 바랍니다.)
미리 감사드립니다.
데이비드
해결책
아마도 비누 API를 사용하는 것이 더 쉬울까요? 진입 점이 있습니다 http : //server/mantis/api/soap/mantisconnect.php .
제휴하지 않습니다 StackOverflow