-1

I've got a problem. For beginning, this is my code:

HttpClient fond = new HttpClient();
using (var client = new HttpClient())
{
    HttpClient.TransportSettings.Credentials = new System.Net.NetworkCredential("username", "pwd");
}
var reponse = await fond.GetStreamAsync("" + TitleNewsGrid.Text);

For me everything is OK but (sorry It's my first app ^^') when I'm compile I found this error:

'System.Net.Http.HttpClient' does not contain a definition for 'TransportSettings'

abatishchev
  • 98,240
  • 88
  • 296
  • 433

1 Answers1

2

Try this

using (var handler = new HttpClientHandler()) 
{
    handler.Credentials = new System.Net.NetworkCredential("username", "pwd");
    using (var client = new HttpClient(handler){  })
    { 
        // code
    } 
}

Not tested ;)

Ceilingfish
  • 5,397
  • 4
  • 44
  • 71
Anuraj
  • 18,859
  • 7
  • 53
  • 79
  • 'System.Net.Http.HttpClient Fond = new HttpClient(); using (var handler = new HttpClientHandler { new System.Net.NetworkCredential("username", "pwd") }) using (var client = new HttpClient(handler)) { var reponse = await Fond.GetStreamAsync("test"+ TitleNewsGrid.Text); {' – Guillaume Fortunier Jul 23 '12 at 10:07
  • I don't find any problem in it. But I am not sure ;) – Anuraj Jul 23 '12 at 10:07
  • Don't work :/ it say Can not initialize type 'System.Net.Http.HttpClientHandler' with a collection initializer because it does not implement 'System.Collections.IEnumerable' – Guillaume Fortunier Jul 23 '12 at 10:10
  • This is my code private async void PremierTest() { HttpClientHandler welcome = new HttpClientHandler(); using (var handler = new HttpClientHandler { Credentials = new System.Net.NetworkCredential("appandr", "e32!cdf") }) using (var client = new HttpClient(handler)) { System.Net.Http.HttpClient Fond = new HttpClient(); var reponse = await Fond.GetStreamAsync("http://ws.jeuxvideo.com/search/mario%20kart" + TitleNewsGrid.Text); – Guillaume Fortunier Jul 23 '12 at 10:19