vb.net code behind GET uri and parse xml results

I am trying to create a uri get with custom headers, the site is suppsoe to return xml back for the request.  I have tried the following code and I get nothing back:

 Dim request As HttpWebRequest
        Dim response As HttpWebResponse = Nothing
        Dim reader As StreamReader
        Dim result As String

        Try
           
            ' Create the web request  
            request = DirectCast(WebRequest.Create("https://app.sandbox.icontact.com/icp/a/412sds566/c/"), HttpWebRequest)

            request.Method = "GET"
            request.ContentType = "text/xml"
            'request.KeepAlive = False

            request.Headers.Clear()
            request.Headers.Add("API-Version", "2.2")
            request.Headers.Add("API-Username", "dfs")
            request.Headers.Add("API-Password", "sdfs")
            request.Headers.Add("API-Appid", "sdfsafdsafadsfasdfadsfadsf")


            ' Get response  
            response = DirectCast(request.GetResponse(), HttpWebResponse)

            ' Get the response stream into a reader  
            reader = New StreamReader(response.GetResponseStream())

            ' Read the whole contents and return as a string  
            result = reader.ReadToEnd()
        Finally
            If response IsNot Nothing Then response.Close()
        End Try

        Return result


This is returning a 406 error and should be returning xml data.  I have used the REST client plugin for firefox with my values and verified that I should be getting xml back.  
SitewizardAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

SitewizardAuthor Commented:
I have made some adjustments and can get the a page until i add the request headers in

 Dim request As HttpWebRequest
        Dim response As HttpWebResponse = Nothing
        Dim reader As StreamReader
        Dim result As String

        Try
           
            ' Create the web request  
            request = DirectCast(WebRequest.Create("https://app.sandbox.icontact.com/icp/a/412sds566/c/"), HttpWebRequest)

            request.Method = "GET"
            request.ContentType = "text/xml"
            'request.KeepAlive = False

            request.Headers.Clear()
            request.Headers.Add("API-Version", "2.2")
            request.Headers.Add("API-Username", "dfs")
            request.Headers.Add("API-Password", "sdfs")
            request.Headers.Add("API-Appid", "sdfsafdsafadsfasdfadsfadsf")


            ' Get response  
            response = DirectCast(request.GetResponse(), HttpWebResponse)

            ' Get the response stream into a reader  
            reader = New StreamReader(response.GetResponseStream())

            ' Read the whole contents and return as a string  
            result = reader.ReadToEnd()
        Finally
            If response IsNot Nothing Then response.Close()
        End Try

        Return result


This is returning a 406 error and should be returning xml data.  I have used the REST client plugin for firefox with my values and verified that I should be getting xml back.  
0
SitewizardAuthor Commented:
Sorry to bother I found the issue,  a 406 error is the client rejecting the format I just had to add request.accept = "text/xml"  and it works

0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Visual Basic.NET

From novice to tech pro — start learning today.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.