?
Solved

vb.net code behind GET uri  and parse xml results

Posted on 2011-10-13
2
Medium Priority
?
402 Views
Last Modified: 2012-05-12
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.  
0
Comment
Question by:Sitewizard
  • 2
2 Comments
 

Author Comment

by:Sitewizard
ID: 36965923
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
 

Accepted Solution

by:
Sitewizard earned 0 total points
ID: 36966104
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

Featured Post

What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

A quick way to get a menu to work on our website, is using the Menu control and assign it to a web.sitemap using SiteMapDataSource. Example of web.sitemap file: (CODE) Sample code to add to the page menu: (CODE) Running the application, we wi…
If you need to start windows update installation remotely or as a scheduled task you will find this very helpful.
Look below the covers at a subform control , and the form that is inside it. Explore properties and see how easy it is to aggregate, get statistics, and synchronize results for your data. A Microsoft Access subform is used to show relevant calcul…
As many of you are aware about Scanpst.exe utility which is owned by Microsoft itself to repair inaccessible or damaged PST files, but the question is do you really think Scanpst.exe is capable to repair all sorts of PST related corruption issues?
Suggested Courses
Course of the Month16 days, 11 hours left to enroll

864 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question