httpcontent

Allow my Tumblr blog's content to be accessed by another page

佐手、 提交于 2019-12-06 12:19:02
问题 I'm attempting to copy all of the actual content from my Tumblr blog using a script I wrote on a different web page, but I'm having a bit of trouble with gaining access to the content. My ajax call is as follows: $.ajax({ url: "http://solacingsavant.tumblr.com/", dataType: 'jsonp', success: function(data) { var elements = $("<div>").html(data)[0].getElementsByTagName("ul")[0].getElementsByTagName("li"); for(var i = 0; i < elements.length; i++) { var theText = elements[i].firstChild.nodeValue;

HttpContent.ReadAsStringAsync causes request to hang (or other strange behaviours)

荒凉一梦 提交于 2019-12-05 03:42:09
We are building a highly concurrent web application, and recently we have started using asynchronous programming extensively (using TPL and async / await ). We have a distributed environment, in which apps communicate with each other through REST APIs (built on top of ASP.NET Web API). In one specific app, we have a DelegatingHandler that after calling base.SendAsync (i.e., after calculating the response) logs the response to a file. We include the response's basic information in the log (status code, headers and content): public static string SerializeResponse(HttpResponseMessage response) {

How do I send arbitrary JSON data, with a custom header, to a REST server?

▼魔方 西西 提交于 2019-12-04 05:20:57
TL;DR -- How do I send a JSON string to a REST host with an auth header? I've tried 3 different approaches found one that works with anonymous types. Why can't I use anonymous types? I need to set a variable called "Group-Name", and a hyphen isn't a valid C# identifier. Background I need to POST JSON but am unable to get the body and the content type correct Function #1 - Works with anonymous types The content type and data is correct, but I don't want to use anonymous types. I want to use a string static void PostData(string restURLBase, string RESTUrl, string AuthToken, string postBody) {

Post JSON HttpContent to ASP.NET Web API

耗尽温柔 提交于 2019-12-03 05:55:13
I have an ASP.NET Web API hosted and can access http get requests just fine, I now need to pass a couple of parameters to a PostAsync request like so: var param = Newtonsoft.Json.JsonConvert.SerializeObject(new { id=_id, code = _code }); HttpContent contentPost = new StringContent(param, Encoding.UTF8, "application/json"); var response = client.PostAsync(string.Format("api/inventory/getinventorybylocationidandcode"), contentPost).Result; This call is returning a 404 Not Found result. The server side API action looks like so: [HttpPost] public List<ItemInLocationModel>

HTTPError Exception Message not displaying when webapi is run on Server vs being run locally

↘锁芯ラ 提交于 2019-11-28 22:19:20
问题 I have a webapi that runs on an IIS7.5 server. It has 3 controllers, and all 3 can be used to access the webapi from calls within my application. I had a error where my base class for my controller was exposing it's functions as public, rather than protected. This caused the server to throw an Internal Server Error 500 (because of an invalid exception thrown "Multiple actions were found that match the request"). It took me a while to drill down on this, because it never triggered the logging

How to set large string inside HttpContent when using HttpClient?

ぃ、小莉子 提交于 2019-11-28 05:18:38
So, I created a HttpClient and am posting data using HttpClient.PostAsync() . I set the HttpContent using HttpContent content = new FormUrlEncodedContent(post_parameters) ; where post_parameters is a list of Key value pairs List<KeyValuePair<string, string>> Problem is, when the HttpContent has a large value (an image converted to base64 to be transmitted) I get a URL is too long error. That makes sense - cause the url cant go beyond 32,000 characters. But how do I add the data into the HttpContent if not this way? Please help. I figured it out with the help of my friend. What you would want

Read HttpContent in WebApi controller

落花浮王杯 提交于 2019-11-27 17:47:34
How can I read the contents on the PUT request in MVC webApi controller action. [HttpPut] public HttpResponseMessage Put(int accountId, Contact contact) { var httpContent = Request.Content; var asyncContent = httpContent.ReadAsStringAsync().Result; ... I get empty string here :( What I need to do is: figure out "what properties" were modified/sent in the initial request (meaning that if the Contact object has 10 properties, and I want to update only 2 of them, I send and object with only two properties, something like this: { "FirstName": null, "LastName": null, "id": 21 } The expected end

Where is HttpContent.ReadAsAsync?

隐身守侯 提交于 2019-11-27 10:32:27
I see in tons of examples on the web using the new HttpClient object (as part of the new Web API) that there should be HttpContent.ReadAsAsync<T> method. However, MSDN doesn't mention this method, nor does IntelliSense find it. Where did it go, and how do I work around it? J... It looks like it is an extension method (in System.Net.Http.Formatting): HttpContentExtensions Class Update: PM> install-package Microsoft.AspNet.WebApi.Client According to the System.Net.Http.Formatting NuGet package page, the System.Net.Http.Formatting package is now legacy and can instead be found in the Microsoft

How do I set up HttpContent for my HttpClient PostAsync second parameter?

ぃ、小莉子 提交于 2019-11-27 06:19:43
public static async Task<string> GetData(string url, string data) { UriBuilder fullUri = new UriBuilder(url); if (!string.IsNullOrEmpty(data)) fullUri.Query = data; HttpClient client = new HttpClient(); HttpResponseMessage response = await client.PostAsync(new Uri(url), /*expects HttpContent*/); response.Content.Headers.ContentType = new MediaTypeHeaderValue("application/json"); response.EnsureSuccessStatusCode(); string responseBody = await response.Content.ReadAsStringAsync(); return responseBody; } The PostAsync takes another parameter that needs to be HttpContent . How do I set up an

How to set large string inside HttpContent when using HttpClient?

丶灬走出姿态 提交于 2019-11-27 00:42:53
问题 So, I created a HttpClient and am posting data using HttpClient.PostAsync() . I set the HttpContent using HttpContent content = new FormUrlEncodedContent(post_parameters) ; where post_parameters is a list of Key value pairs List<KeyValuePair<string, string>> Problem is, when the HttpContent has a large value (an image converted to base64 to be transmitted) I get a URL is too long error. That makes sense - cause the url cant go beyond 32,000 characters. But how do I add the data into the