![]() |
|
#1
|
|||
|
|||
|
Moin,
I want to send an HTTP post using VBA. It works quite well when sent WITHOUT a payload. Code:
Private Function http_post(url As String, payload As String) As String
Dim req As MSXML2.ServerXMLHTTP60
Set req = New MSXML2.ServerXMLHTTP60
With req
.Open "POST", url, False
.setRequestHeader "Accept:", "application/json"
.setRequestHeader "Content-Type:", "application/json"
.setRequestHeader "X-Api-Key:", "---"
.send
http_post = .responseText
End With
End Function
The working PYTHON code for this looks like this: Code:
import requests
url = "https://api.bavest.co/v0/quote"
payload = { "isin": "US02079K3059" }
headers = {
"accept": "application/json",
"content-type": "application/json",
"x-api-key": "---"
}
response = requests.post(url, json=payload, headers=headers)
print(response.text)
For this I extended my code as follows: Code:
Private Function http_post(url As String, payload As String) As String
Dim req As MSXML2.ServerXMLHTTP60
Set req = New MSXML2.ServerXMLHTTP60
payload = "{ ""isin"": ""US02079K3059"" }"
With req
.Open "POST", url, False
.setRequestHeader "Accept:", "application/json"
.setRequestHeader "Content-Type:", "application/json"
.setRequestHeader "X-Api-Key:", "---"
.send payload
http_post = .responseText
End With
End Function
Quote:
Code:
payload = "{ 'isin': 'US02079K3059' }"
Quote:
Code:
payload = "{ ""isin"": ""US02079K3059"" }"
Code:
payload = "{ 'isin': 'US02079K3059' }"
What am I doing wrong here? Greetings Pf@nne |
|
|
|
Similar Threads
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| Problem with a post in the Word forum - goes to a static page | Charles Kenyon | Forum Support | 1 | 12-06-2023 08:53 AM |
| Get Zip code detail via JSON in VBA. | Mangesh1212 | Excel Programming | 1 | 12-18-2018 07:26 PM |
| http/1.0 404 not found | Powerpoint User | PowerPoint | 2 | 11-20-2016 11:10 PM |
| How to Work with JSON in word-vba | PRA007 | Word VBA | 1 | 05-01-2016 02:53 PM |
| Outlook http server | joelwelford | Outlook | 0 | 09-07-2015 10:00 AM |