Mantis BT通过“WinHttp.WinHttpRequest.5.1”导出请求

时间:2009-08-13 14:41:25

标签: vba winhttp mantis winhttprequest

我的老板让我将公司的Mantis错误数据库导出到Excel,但是他不能让我访问SQL Server,并且该过程必须自动化。

我可以使用的唯一的东西是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代码)之前的行,ResponseText显示“2200个错误”,所以一切都很好,直到最后一个查询(csv_export.php)。该脚本通过浏览器调用时显示与调用它的页面完全相同(如果页面显示2个错误,则CSV将包含2个错误)。在IE / Firefox中显示我的2200个错误,CSV给我带来了2200个错误。 但是在Excel中,即使ResponseText显示2200个错误,CSV也会给我带来624个错误......好像我没有调用“高级过滤器”页面:(

我希望有人能理解并帮助我;)

提前致谢,

大卫

1 个答案:

答案 0 :(得分:0)

也许您更容易使用SOAP API?入口点位于http://server/mantis/api/soap/mantisconnect.php