-
Notifications
You must be signed in to change notification settings - Fork 12
/
Copy pathvalidateRecipient.vb
36 lines (32 loc) · 1.56 KB
/
validateRecipient.vb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
Imports System.IO
Imports System.Net
Namespace Recipient_Validation
Public Class RVsample
Public Shared Sub Main()
Const url As String = "https://api.sparkpost.com/api/v1/recipient-validation/single/recipient="
Dim apiKey As String = System.Environment.GetEnvironmentVariable("SPARKPOST_API_KEY", EnvironmentVariableTarget.User)
' replace this line with some loop to pull from a data source
Dim recipient As String = "[email protected]"
' Create a request for the URL.
Dim client As WebRequest = WebRequest.Create(url & recipient)
Console.WriteLine(client.Headers)
client.Headers.Add("Authorization", apiKey)
client.Headers.Add("Accept", "application/json")
' may need to tweak this error handling
Try
Using dataStream As Stream = client.GetResponse().GetResponseStream()
' Open the stream using a StreamReader for easy access.
Dim reader As New StreamReader(dataStream)
' Read the content.
Dim responseFromServer As String = reader.ReadToEnd()
' Display the content.
Console.WriteLine(responseFromServer)
End Using
' client.GetResponse().Close()
Catch e As HttpListenerException
Console.WriteLine(vbLf & "Exception Caught!")
Console.WriteLine("Message :{0} ", e.Message)
End Try
End Sub
End Class
End Namespace