以HTTP格式发送JSON文件(VB6)

时间:2017-07-25 01:46:20

标签: json http post vb6

我现在可以使用此代码在HTTP中发送纯文本了。

Public Function WebRequest(url As String, jsonFile As String) As String
    'In this string, I am putting the parsed JSON file
    jsonFile = ReadTextFile(jsonFile)

    Dim http As MSXML2.XMLHTTP60
    Set http = CreateObject("MSXML2.ServerXMLHTTP")

    http.Open "POST", url, False
    http.send jsonFile

    WebRequest = http.responseText
    Set http = Nothing
End Function

这个函数只是解析JSON文件,我有CommonDialog控件来选择文件。

Public Function ReadTextFile(sFilePath As String) As String
   On Error Resume Next

   Dim handle As Integer
   If LenB(Dir$(sFilePath)) > 0 Then

      handle = FreeFile
      Open sFilePath For Binary As #handle
      ReadTextFile = Space$(LOF(handle))
      Get #handle, , ReadTextFile
      Close #handle
   End If

End Function

这个简单的代码将成功地在HTTP中发布文本,但我想要的是发布确切的JSON文件,而不仅仅是文本内部的文本。

0 个答案:

没有答案