Creating contact API call times out from site but works from RestClient testing app

Participant

Creating contact API call times out from site but works from RestClient testing app

Hello!


Ok I am trying to create a contact using VB.Net (ASP.Net) 2008. When running the script from the website, it hangs and eventually times out. When running from the RestClient testing app, it runs fine. I'm going to skip showing the XML building logic and just show the final xml...here is the vb code:


 


(vb xml stringbuilder logic)


 


1. Here's the final xml that is created


<?xml version="1.0" encoding="utf-8" standalone="yes"?>

<entry xmlns="http://www.w3.org/2005/Atom">

    <title type="text"> </title>

    <updated>2008-07-23T14:21:06.407Z</updated>

    <author> </author>

    <id>data:,none</id>

    <summary type="text">Contact</summary>

    <content type="application/vnd.ctct+xml">

        <Contact xmlns="http://ws.constantcontact.com/ns/1.0/">

            <EmailAddress>mark@testingemail.com</EmailAddress>

            <OptInSource>ACTION_BY_CUSTOMER</OptInSource>

            <ContactLists>

                <ContactList id="http://api.constantcontact.com/ws/customers/{our username}/lists/1" />

            </ContactLists>

        </Contact>

    </content>

</entry>


 


2. Here's the function call:


strResult = objDB.SendConstantContactRequest(0, "https://api.constantcontact.com/ws/customers/{our username}/contacts", 1, strFormFields)


 


3. Here's the function


Public Function SendConstantContactRequest(ByVal bytPostType As Byte, ByVal strTargetUrl As String, ByVal bytContentType As Byte, ByVal strFormFields As String) As String


Dim objTarget As New Uri(strTargetUrl)

Dim strResult As String


'BUILD REQUEST OBJECT

Dim objRequest As HttpWebRequest = TryCast(WebRequest.Create(objTarget), HttpWebRequest)


objRequest.Credentials = New NetworkCredential("{API Key}%{username}", "{password}")


Select Case bytPostType

    Case 0

        objRequest.Method = WebRequestMethods.Http.Post

        objRequest.ContentLength = strFormFields.Length

    Case 1

        objRequest.Method = WebRequestMethods.Http.Get

    Case 2

        objRequest.Method = WebRequestMethods.Http.Put

End Select


Select Case bytContentType

    Case 0

        objRequest.ContentType = "application/x-www-form-urlencoded"

    Case 1

        objRequest.ContentType = "application/vnd.ctct+xml"

    Case 2

        objRequest.ContentType = "application/atom+xml"

End Select


Dim objResponse As HttpWebResponse = TryCast(objRequest.GetResponse(), HttpWebResponse)

Dim objReader As StreamReader = New StreamReader(objResponse.GetResponseStream)


strResult = objReader.ReadToEnd


Return strResult


End Function


 


Any help would be greatly appreciated!...


Thanks.


Mark

Mark Crouch


Bizmodus.com

1 REPLY 1
Employee

While I am not overly familiar with vb.net, it appears that your function call:


 


strResult = objDB.SendConstantContactRequest(0, "https://api.constantcontact.com/ws/customers/{our username}/contacts", 1, strFormFields)


 


is specifying "1" as your 3rd parameter, which is calling for the application/vnd.ctct+xml content-type. Try changing your third argument from this function call to "2" (application/atom+xml), and this should resolve your issue.

David J

Developer Portal

View API documentation, code samples, get your API key.

Visit Page