1

为了管理来自特定客户端的错误,我正在考虑让应用程序将当前的错误日志文件发送给我,也许是在它启动时。

在 VB6/XP 环境中实现这一目标的最佳方法是什么?

电子邮件可能很简单,但我想这可能会触发各种防病毒/防火墙保护。

连接到网络服务器可能会更好。在这种情况下,应用程序是否仍需要打开 Windows 防火墙?

4

1 回答 1

0

XMLHTTP用来上传这样的客户端错误日志:http ://wqweto.wordpress.com/2011/07/12/vb6-using-wininet-to-post-binary-file/

Private Sub pvPostFile(sUrl As String, sFileName As String, Optional ByVal bAsync As Boolean)
    Const STR_BOUNDARY  As String = "3fbd04f5-b1ed-4060-99b9-fca7ff59c113"
    Dim nFile           As Integer
    Dim baBuffer()      As Byte
    Dim sPostData       As String

    '--- read file
    nFile = FreeFile
    Open sFileName For Binary Access Read As nFile
    If LOF(nFile) > 0 Then
        ReDim baBuffer(0 To LOF(nFile) - 1) As Byte
        Get nFile, , baBuffer
        sPostData = StrConv(baBuffer, vbUnicode)
    End If
    Close nFile
    '--- prepare body
    sPostData = "--" & STR_BOUNDARY & vbCrLf & _
        "Content-Disposition: form-data; name=""uploadfile""; filename=""" & Mid$(sFileName, InStrRev(sFileName, "\") + 1) & """" & vbCrLf & _
        "Content-Type: application/octet-stream" & vbCrLf & vbCrLf & _
        sPostData & vbCrLf & _
        "--" & STR_BOUNDARY & "--"
    '--- post
    With CreateObject("Microsoft.XMLHTTP")
        .Open "POST", sUrl, bAsync
        .SetRequestHeader "Content-Type", "multipart/form-data; boundary=" & STR_BOUNDARY
        .Send pvToByteArray(sPostData)
    End With
End Sub

Private Function pvToByteArray(sText As String) As Byte()
    pvToByteArray = StrConv(sText, vbFromUnicode)
End Function
于 2012-05-02T19:57:24.163 回答