1

Request your help to solve the below issue,I am struck for two days,

vba run time error '- 2146697208 (800c0008 )': The download of the specified resource has failed

This is my code for your reference:

Sub telebot15status155555()

   'Program Excel Messeger
   ' Purpose : Send Message to Telegram
   ' Author : John Eswin Nizar
   ' Date : 09 October 2017

    Dim objRequest As Object
    Dim strChatId As String
    Dim strMessage1 As String
    Dim strMessage2 As String
    Dim strPostData As String
    Dim strResponse As String

    strChatId = "@messstatus"
    strMessage1 = ""
    strMessage2 = Now()

    'strMessage = "hallo"

     strPostData = "chat_id=" & strChatId & "&text=" & strMessage1 & strMessage2

     Set objRequest = CreateObject("MSXML2.XMLHTTP")

     With objRequest
         .Open "POST", "https://api.telegram.org/sendMessage?", False
         .setRequestHeader "Content-Type", "application/x-www-form-urlencoded"
         .send (strPostData)
         GetSessionId = .responseText
         MsgBox GetSessionId
     End With
End Sub
Alex K.
  • 171,639
  • 30
  • 264
  • 288

1 Answers1

0

My advice here is to perform this API call in Chrome with DevTools open. Or access the page, where this happens, and find the Request on the 'Network' tab. Then look at the headers.

debug.print strPostData is returning:

chat_id=@messstatus&text=2/7/2020 9:40:23 AM

That format does not look correct for an API that is form-urlencoded. You need to see what the website is actually sending and receiving in the DevTools in order to replicate it.

IOW, The resource isn't found because the API is incorrectly formatted. From the base api, it looks like its actually a QueryString too because it ends with ? which might mean you have to url-encode format the POST Data into the QueryString for the main HTTP request. Have a look here: Pass Parameters in VBA HTTP Post Request

Peyter
  • 474
  • 3
  • 14