dotnet-httpclient

VSO REST API - Getting user profile image only works with basic authentication?

别说谁变了你拦得住时间么 提交于 2019-12-08 15:00:53
问题 I'm using the VSO REST API to get all members in a team, from there I'm getting the ImageUrl of the member. If I just bind an Image control to ImageUrl it's blank because VSO requires that I be signed in to get a profile picture... so I created a HttpClient and set my Authorization to OAuth and gave it my access token. This just returns a 403 : Forbidden response... But if I use basic authentication, then everything works fine? Is basic authentication the only method to get profile images

async await execution windows phone 8

无人久伴 提交于 2019-12-08 13:58:26
I am new to async and await style of programming. How can I solve the following problem: I am calling the below code first. The problem here is that the first line is awaiting which need to populate the categoriesvm.Categorieslist , which it does not, but the second line is called. (which I think is the default behaviour of await) How can I make sure that the second line is called only when the categoriesvm.Categorieslist is populated in the first line? protected override void OnNavigatedTo(System.Windows.Navigation.NavigationEventArgs e) { categoriesvm.GetCategories(); BookCategories

ASP.NET using analytics Reporting API does not work on server

岁酱吖の 提交于 2019-12-08 11:50:13
问题 When I run my asp.net application on local host everything works great but when i publish my app on the web server this error shows up: Method 'ApplyAuthenticationToRequest' in type 'Google.Apis.Authentication.OAuth2.OAuth2Authenticator`1' from assembly 'Google.Apis.Authentication.OAuth2, Version=1.4.0.28223, Culture=neutral, PublicKeyToken=null' does not have an implementation. Here is part of the code that uses analytic ............................................. //This is the API url

Control total number of tasks when using Async/Await in a recursive function

六月ゝ 毕业季﹏ 提交于 2019-12-08 11:31:29
I have written this code. It recursively creates folders in the web system by making REST Calls. So basically, it creates a folder for the root node, then gets all the child nodes and parallely and recursively calls itself. (for each child) the only problem with the code is that if a node has too may children OR if the hierarchy is too deep, then I start getting "TaskCancellation" errors. I have already tried increasing the timeout to 10 minutes.. but that does not solve the problem. So my question is how can I start say 50 tasks, then wait for something to get freed and proceed only when

How can I use ReadAsAsync<T> with this data schema?

不打扰是莪最后的温柔 提交于 2019-12-08 09:15:32
问题 I am using System.Net.Http.HttpClient, the version currently available in NuGet, to retrieve data from a service in json format. The data roughly looks like this: { "schema": "Listing", "data": { "key": "28ba648c-de24-45d4-a7d9-70f810cf5438", "children": [{ "kind": "type1", "data": { "body": "Four score and seven years ago...", "parent_id": "2qh3l", "report_count": 0, "name": "c4j6yeh" } }, { "kind": "type3", "data": { "domain": "abc.def.com", "flagged": true, "category": "news", "saved":

Posting a Custom type with HttpClient

偶尔善良 提交于 2019-12-08 09:00:08
问题 I have a custom dto class: public class myObject { public string Id { get; set; } public string Name { get; set; } } and a Controller using Web Api (4.5 .net framework) [HttpPost] public IHttpActionResult StripArchiveMailboxPermissions(myObject param) { DoSomething(param); return OK(); } The client side only has 4.0 .net framework So I won't be able to use the PostAsJsonAsync() method. what is the solution to pass the object from my client to the server? I have tried somethinig like the

How to listen to a keep-alive HttpResponseMessage until it's closed?

╄→尐↘猪︶ㄣ 提交于 2019-12-08 08:36:59
问题 I'm using HttpClient to send an asynchronous POST request to a remote web server. That remote web server responds with the Connection header set to keep-alive . Eventually, it will close the connection. What I can't figure out how to do is keep receiving data until the connection is set to close. For example, consider the following code: HttpClient client = new HttpClient(); string requestUri = ...; //My GET uri string content = ...; //url-encoded contents of the request HttpResponseMessage

JSON to Dynamic Object vs. Strongly Typed Object

我与影子孤独终老i 提交于 2019-12-08 08:14:36
问题 I'm not sure if I don't get the big picture or if I just miss something but what are the benefits of parsing a JSON-String to a dynamic object? If I have a class like this class Product { public string Name { get; set; } public double Price { get; set; } public string Category { get; set; } } and I use the HttpClient to get the object like this Product product = await response.Content.ReadAsAsync<Product>(); What do I benefit from this code? string content = await response.Content

Why does HttpClient appear to deadlock here?

时光总嘲笑我的痴心妄想 提交于 2019-12-08 07:06:58
问题 I have an API made in a portable class library which needs to reach out to platform specific APIs for sending HTTP requests. Here is the method I wrote to do an HTTP POST on WinRT: public bool Post(IEnumerable<KeyValuePair<string, string>> headers, string data) { bool success = false; HttpClient client = new HttpClient(new HttpClientHandler {AllowAutoRedirect = false}); foreach (var header in headers) { client.DefaultRequestHeaders.Add(header.Key, header.Value); } try { var task=client

Override Host in HttpClient

柔情痞子 提交于 2019-12-08 05:43:47
问题 I'm using HttpClient but it has problems with DNS resolve (it is using the sync method for this) So I use another lib for doing DNS queries and now I'm tryging to get custom urls by IP but I need to replace Host header. For example I have url http://fb.com but I need to get http://1.1.1.1 with Host set to fb.com I've tryied: _req = new HttpRequestMessage(HttpMethod.Get, newUri.ToString()); _req.Headers.Host = uri.Host; _httpClient.DefaultRequestHeaders.Host = uri.Host; but this doesn't work.