Answer the question
In order to leave comments, you need to log in
How to read text correctly in VBA?
I am using the following function:
Option Explicit
Function GetData(ByVal api As String, ByVal content As String)
Restart: Dim sUrl As String
sUrl = "http://127.0.0.1/api/" + api
Dim oRequest As Object
Dim sResult As String
Dim sResult2 As String
On Error GoTo Err_DoSomeJob
Set oRequest = CreateObject("WinHttp.WinHttpRequest.5.1")
With oRequest
.Open "GET", sUrl, True
.SetRequestHeader "Content-Type", "application/x-www-form-urlencoded; charset=windows-1251"
.Send content
.WaitForResponse
sResult = .ResponseText
Debug.Print sResult
sResult2 = .Status
Debug.Print sResult2
End With
Exit_DoSomeJob:
On Error Resume Next
GetData = sResult
Set oRequest = Nothing
If sResult2 <> "200" Then
GoTo Restart
End If
Exit Function
Err_DoSomeJob:
'MsgBox Err.Description, vbExclamation, Err.Number
Resume Exit_DoSomeJob
End Function
Answer the question
In order to leave comments, you need to log in
Apparently the text comes in Unicode encoding. Try converting text with StrConv
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question