Closed
Description
Hi,
I'm using VBA-Web to post sheet in csv and images as base64 encoded strings to my web server. The server responds with an empty JSON with status 200. When using the macro in Windows Excel 2003 it works ok but on Mac Excel 2011 I get an error
Run-time error '-2147210493 (80042b03)':
Method 'Execute' of object 'WebClient' failed
The debug is highlighting the row with
Set response = expClient.Execute(expRequest)
The macro code looks like this
Sub test()
Dim token As String
Dim i As Long
Dim requestBody As String
Dim imageString As String
Application.StatusBar = "Sending csv data..."
Dim expClient As New WebClient
expClient.BaseUrl = ApiBaseUrl()
Dim expRequest As New WebRequest
expRequest.Resource = "/excel_data"
expRequest.Method = WebMethod.HttpPost
expRequest.RequestFormat = WebFormat.PlainText
expRequest.ResponseFormat = WebFormat.json
expRequest.AddHeader "X-Api-Access-Token", Range("L1")
requestBody = Join2d(Worksheets("Sheet1").Range("A1:I37").Value, vbCrLf, ",")
expRequest.Body = requestBody
Dim response As WebResponse
Set response = expClient.Execute(expRequest)
If response.StatusCode = WebStatusCode.ok Then
token = response.Data("token")
i = 1
For Each img In Worksheets("Sheet1").Shapes
Application.StatusBar = "Sending image " & i
imageString = readImageToString(img)
requestBody = Encode64(imageString)
Set expRequest = New WebRequest
expRequest.Resource = "/image_data"
expRequest.Method = WebMethod.HttpPost
expRequest.RequestFormat = WebFormat.PlainText
expRequest.ResponseFormat = WebFormat.json
expRequest.AddHeader "X-Api-Access-Token", Range("L1")
expRequest.AddHeader "X-Token", token
expRequest.AddHeader "X-Image-Name", "test.jpg"
expRequest.Body = requestBody
Set response = expClient.Execute(expRequest)
If response.StatusCode <> WebStatusCode.ok Then
MsgBox ("Sending data error:" & vbCrLf & response.Content)
Exit Sub
End If
i = i + 1
Next img
Else
MsgBox ("Sending data error:" & vbCrLf & response.Content)
Exit Sub
End If
End Sub
Do you have ideas about why this is happening? Any workarounds?
Metadata
Metadata
Assignees
Labels
No labels