c# Httpclient API Get

1,135 views
Skip to first unread message

Spike Heath

unread,
May 1, 2014, 11:25:42 AM5/1/14
to orcid-a...@googlegroups.com
Can anyone see what's up with the code below.  I'm not getting any XML returned just this:

StatusCode: 200, ReasonPhrase: 'OK', Version: 1.1, Content: System.Net.Http.StreamContent, Headers:
{
  Transfer-Encoding: chunked
  Connection: keep-alive
  Vary: Accept-Encoding
  Access-Control-Allow-Origin: *
  Date: Thu, 01 May 2014 15:24:07 GMT
  Server: nginx/1.1.19
  Content-Type: application/xml; charset=UTF-8
}



The Code
=========
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading;
using System.Threading.Tasks;
using System.Data.SqlClient;
using System.Net.Http;
using System.Net.Http.Headers;
using System.IO;
using System.Diagnostics;

namespace orcidTestBed
{
    class Program
    {
        static void Main(string[] args)

        {


            var client = new HttpClient();
            client.BaseAddress = new Uri(_address);
            client.DefaultRequestHeaders.Accept.Add(new MediaTypeWithQualityHeaderValue("application/xml"));

            HttpResponseMessage orcidresponse = client.GetAsync(_address).Result;

            Console.WriteLine(orcidresponse.ToString());
            
            System.Threading.Thread.Sleep(5000);
        }
    }
}

Robert Peters

unread,
May 15, 2014, 4:56:08 PM5/15/14
to orcid-a...@googlegroups.com
Hi Spike,
I haven't done any #C programming but I've noticed you're using a GetAsync. However I suspect you can't just call Result and instead must use something like ContinueWith.

Cheers,
Rob
Reply all
Reply to author
Forward
0 new messages