Here is my code, please let me know what I'm missing
HERE IS THE CODE
Protected Sub lnkButton_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles lnkButton.Click
Dim sUsername As String = ConstantContact.UserName
Dim sPassword As String = ConstantContact.Password
Dim sUri As String = "http://api.constantcontact.com/ws/customers/" & sUsername & "/activities"
Dim sListUri As String = "http://api.constantcontact.com/ws/customers/" & sUsername & "/lists/1"
Dim sAPIKey As String = ConstantContact.APIKey
'Setup an HttpWebRequest
Dim address As New Uri(sUri)
Dim request As HttpWebRequest = TryCast(WebRequest.Create(address), HttpWebRequest)
request.Credentials = New NetworkCredential((sAPIKey & "%" & sUsername), sPassword)
request.Method = "POST"
request.ContentType = "application/x-www-form-urlencoded"
'Build data string
Dim data As New StringBuilder()
data.Append("activityType=" + HttpUtility.UrlEncode("ADD_CONTACTS", Encoding.UTF8))
data.Append("&data=" + HttpUtility.UrlEncode(("Email Address,Email Type,First Name,Last Name" & Chr(10)), Encoding.UTF8))
data.Append(HttpUtility.UrlEncode((txtSubscribe.Text & ", HTML, , "), Encoding.UTF8))
data.Append("&lists=" + HttpUtility.UrlEncode(sListUri))
Dim byteData As Byte() = UTF8Encoding.UTF8.GetBytes(data.ToString())
Dim st As String = String.Empty
request.ContentLength = byteData.Length
Using postStream As Stream = request.GetRequestStream()
postStream.Write(byteData, 0, byteData.Length)
End Using
Using response As HttpWebResponse = TryCast(request.GetResponse(), HttpWebResponse)
Dim reader As New StreamReader(response.GetResponseStream())
st = reader.ReadToEnd()
End Using
End Sub
HERE IS THE ERROR
|
The problem is that your request URI is not sent over https. You would need to use the correct URI for Authentication to work. For more information on Authentication, please see here: developer.constantcontact.com/doc/authenticationBasic.
It should be as simple as changing:
Dim sUri As String = "http://api.constantcontact.com/ws/customers/" & sUsername & "/activities"
to
Dim sUri As String = "https://api.constantcontact.com/ws/customers/" & sUsername & "/activities"
Perfect, that was it.. thank you.