2

I have an application that I'd like to consume an API for a SMS sending service that takes the following variables : username, from, message & to. It has a header of the apikey and it's value. I used WinSock that was working but the service provider has since advised that the request needs to be a https request. I'm new to web development and VB6 application was written way back.

This is my post request

POST /version1/messaging HTTP/1.0
Host: api.africastalking.com
Content-Type: application/x-www-form-urlencoded
Content-Length: 141
ApiKey: 37236e3e47654ee7773bbbc78a4049fde7d3390dbb70f630b19f4aeab7b0ce88

username=xxxxxxx&message=Hello%20Kind%20regards%2C%20xxx%20xxxx%20xxx%2E%20Tel%2E%200721000111&to=%2B254721000111&from=xxxx

It works in postman. I can provide the variables via email.

This is the response

HTTP/1.1 308 Permanent Redirect
Date: Tue, 06 Jun 2023 18:40:40 GMT
Content-Type: text/html
Content-Length: 164
Connection: close
Location: https://api.africastalking.com/version1/messaging

    <html>
    <head><title>308 Permanent Redirect</title></head>
    <body>
    <center><h1>308 Permanent Redirect</h1></center>
    <hr><center>nginx</center>`your text`
    </body>
    </html>
StayOnTarget
  • 11,743
  • 10
  • 52
  • 81

1 Answers1

0

With VB6 you can use the WinHttpRequest object to place your request.

First you will need to add a Reference to Microsoft WinHTTP Services, version 5.1 from the Project > References... menu.

You will then be able to create a WinHttpRequest object:

Dim objWinHTTPRequest As New WinHttpRequest
Dim sBody As String

With objWinHTTPRequest
    
    sBody = "username=xxxxxxx&message=Hello%20Kind%20regards%2C%20xxx%20xxxx%20xxx%2E%20Tel%2E%200721000111&to=%2B254721000111&from=xxxx"
    
    .open "POST", "api.africastalking.com", False
    .setRequestHeader "ApiKey", "37236e3e47654ee7773bbbc78a4049fde7d3390dbb70f630b19f4aeab7b0ce88"

    .send sBody

End With

If you need to add a Client Certificate, use SetClientCertificate method:

objWinHTTPRequest.SetClientCertificate("LOCAL_MACHINE\Personal\My Middle-Tier Certificate")
Étienne Laneville
  • 4,697
  • 5
  • 13
  • 29
  • Thank you so much, I have tried the code and I get this error. "Error Occurred in the Secure Channel Support" Any idea on what I need to handle? I have added the client certificate code. – user2614086 Jun 07 '23 at 07:02
  • 1
    You might want to try setting supported protocols manually with `.Option(WinHttpRequestOption_SecureProtocols) = SecureProtocol_ALL Or SecureProtocol_TLS1_1 Or SecureProtocol_TLS1_2` before calling `Send` method. For Win7 and earlier versions of Windows you can try the same code with the [Http Request Replacement](https://github.com/wqweto/VbAsyncSocket/releases) ActiveX DLL which supports TLS 1.3 on Win7 and below. – wqw Jun 07 '23 at 14:06