如何让app自动发送日志文件支持?

时间:2012-05-02 09:15:24

标签: vb6 windows-xp logging error-logging

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

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

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

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

1 个答案:

答案 0 :(得分: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
相关问题