问题标签 [httpcontent]

For questions regarding programming in ECMAScript (JavaScript/JS) and its various dialects/implementations (excluding ActionScript). Note JavaScript is NOT the same as Java! Please include all relevant tags on your question; e.g., [node.js], [jquery], [json], [reactjs], [angular], [ember.js], [vue.js], [typescript], [svelte], etc.

0 投票
1 回答
1437 浏览

c# - 标头 HttpContent 'System.InvalidOperationException'

让我从显示代码开始:

我不能透露网址。

问题是它没有设置会话变量,并且内容返回了标题,标题也显示在提琴手中。异常'System.InvalidOperationException' 我已经尝试了最明显的选项,它肯定会正确响应,并且我以某种方式将标题变成了一个字符串,但我不记得如何了。

0 投票
2 回答
15782 浏览

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

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 from my webapi. From this dicussion here, I discovered that the error that was happening was happening before an Application_Error function would catch it to log it. So I added the below code to my global.asax of my webapi, and I can now log errors like this.

BUT, my problem now, when I cause an Internal Server Error 500 exactly like above, on my local machine running my webapi, I get a log exactly how I wish to see it with the "ExceptionMessage" of "Multiple actions were found that match the request" spelled out as the reason for the Internal Server Error. But when deploy this exact code to the server, and use the webapi from there, my log only displays "Message" : "An error has occurred" and does not show me the "ExceptionMessage", even though I can see that the exception is being thrown using PerfView. I just need to be able to get my server logs to show the same information as what my local log displays.

Server Log Example:

Local Log Example:

0 投票
3 回答
67220 浏览

c# - 使用 HttpClient 时如何在 HttpContent 中设置大字符串?

因此,我创建了一个HttpClient并正在使用HttpClient.PostAsync().

我设置HttpContent使用

HttpContent content = new FormUrlEncodedContent(post_parameters); 哪里post_parameters是键值对列表List<KeyValuePair<string, string>>

问题是,当HttpContent值很大时(将图像转换为 base64 进行传输),我得到一个 URL 太长的错误。这是有道理的——因为网址不能超过 32,000 个字符。HttpContent但是如果不是这种方式,我该如何将数据添加到其中?

请帮忙。

0 投票
1 回答
40050 浏览

c# - 将 JSON HttpContent 发布到 ASP.NET Web API

我有一个托管的 ASP.NET Web API 并且可以很好地访问 http get 请求,我现在需要将几个参数传递给 PostAsync 请求,如下所示:

此调用返回 404 Not Found 结果。

服务器端 API 操作如下所示:

只是为了确认我在 Web API 上的路线如下所示:

我假设我错误地传递了 JSON HttpContent,为什么会返回状态 404?

0 投票
1 回答
5180 浏览

c# - 使用 PostAsync、HttpClient 和 Json 从 Windows Phone 8.1 调用 REST

我的问题非常类似于 Calling MVC4 WebAPI methods from C# Metro UI Client using PostAsync, HttpClient & Json这不足以解决我的问题。

这是我在 Windows Phone 8.1 项目中的代码:

responseBody 总是会返回一小段带有https://m.vente-privee.com/f/fail_int.png的 html ,表示调用失败。Chrome 中 Postman内置的相同调用返回以下成功字符串:

邮递员通话成功截图

你知道我在 C# 代码中做错了什么吗?谢谢。

0 投票
1 回答
195 浏览

c# - 如何执行网站上的所有 http 链接?

我有一个任务是在 C# 上编写一个程序,它可以从网站上找到所有 http 链接。现在我为它写了一个这样的函数:

使用这个函数,我将网页内容加载到字符串中,然后我解析这个字符串并将结果写入数组,使用“href”-splitter,然后我检查字符串上的每个数组单元,其中包含“href”子字符串。所以我可以获得字符串,其中包含 http 链接。问题开始于字符串拆分时,因为无法找到 http 链接,在我看来这是由于该字符串的内容格式。如何解决?

0 投票
1 回答
1402 浏览

c# - HttpResponseMessage System.InvalidOperationException

我有一个相当简单的问题,我认为对于大脑来说很容易解决。这只是在 Google 上尝试了不同的查询,但没有弹出任何内容,但这就是我在这里的原因。

这是错误: System.InvalidOperationException

基本上这里的这段代码会抛出这个错误

Fiddler 中的位置如下所示:

位置:https ://www.redirecturlishere.com/blah

这是整个函数:

有关错误的更多详细信息,“附加信息:错误使用的标头名称。确保请求标头与 HttpRequestMessage 一起使用,响应标头与 HttpResponseMessage 一起使用,内容标头与 HttpContent 对象一起使用。”

我认为没有太多要解释的了,所以我就先说这么多。

0 投票
1 回答
3594 浏览

c# - 使用 IHttpContent 发出 HttpClient.PutAsync 请求

如何创建具有请求正文IHttpContent的内容的对象?PutAsync

请求是这样的:


我正在使用Windows.Web.HttpClient图书馆。

0 投票
0 回答
577 浏览

c# - 无法在 HttpClient 中读取 GetAsync 的响应,我有奇怪的迹象而不是 json

我有简单的获取请求HttpClient

response.Content.ReadAsStringAsync()我有奇怪的迹象,而在提琴手我可以看到正常的 json:

0 投票
1 回答
1050 浏览

java - 从 HttpObject Netty 获取 HttpContent - Java

我正在与 Netty 合作。我有一个 HttpObject,我需要内容(HttpContent)。演员阵容不行。那我该怎么办?

问候丹尼尔