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

发布于 2024-08-01 23:49:14 字数 2234 浏览 4 评论 0原文

我的老板要求我将公司的 Mantis bug 数据库导出到 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 个错误......就好像我没有调用“高级过滤器”页面:(

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

提前致谢,

大卫

My boss asked me to export the corp's Mantis bugs database to Excel, but he can't give me access to the SQL Server, and the process has to be automated.

The ONLY thing I can use is Excel (no ODBC, no manual export).

So I managed to do this :

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 the code) The line before, the ResponseText showed "2200 bugs", so everything was fine until the last query (csv_export.php). The script, when called via a browser, shows exactly the same as the page which called it (if the page showed 2 bugs, the CSV will contain 2 bugs). With my 2200 bugs shown in IE / Firefox, the CSV brings me 2200 bugs.
But in Excel, even if the ResponseText shows 2200 bugs, the CSV brings me 624 bugs... As if I hadn't called the "Advanced Filter" page :(

I hope someone can understand and help me ;)

Thanks in advance,

David

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

南城追梦 2024-08-08 23:49:14

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

Perhaps it would be easier for you to use the SOAP API? The entry point is at http://server/mantis/api/soap/mantisconnect.php .

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文