问题标签 [httpresponsemessage]
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.
c# - 从 HttpResponseMessage 读取字符串
我正在尝试从我的 HttpResponseMessage 中读取字符串。这是我的控制器。
它以字符串格式返回数字。如何读取表单上的字符串?
rest - What HTTP status code should a Web API return after successful completion, if it performed both UPDATES and INSERTS?
This is a follow up question on my earlier post at PUT or POST HTTP verb when calling API endpoint which performs both UPDATE and INSERT?
I have a RESTful Web API (written in ASP .Net Core 2.1) which receives a "change-log" from the consuming client app. This is a JSON class containing all the modifications to the database that were performed on the client app while it was working in offline mode. Once the client app goes online, it synchronizes its database with an online/live database by sending the API all the changes that have happened since the last sync. So it sends the API a change-set/change-log with a bunch of UPDATE, INSERT and DELETE lists for the various tables/objects.
On the API side, I don't actually delete anything from the live database - I simply flag things as deleted (so I set a boolean field to true, i.e. deleted = true). So technically, the API only performs INSERTS and UPDATES on the database
What status code should the action method of the API return upon successful completion? Since it is doing a combination of both INSERTS and UPDATES, should it return a 201 Created? Or simply a 200 OK? Or a 200 OK if only updates were performed, else a 201 if any inserts were performed? Also, in the response body, since I'm not actually planning on returning any ID's or objects in the body (since multiple objects wouldve been updated and inserted), I would like to return just plain text saying how many objects were updated, how many were inserted and how many were flagged as deleted. Is this possible, or even a good idea?
Thanks
java - Jersey 响应的原因短语在 tomcat 7 和 8.5 中不一致
我在一台服务器中使用 Tomcat 8.5,在不同服务器中使用 Tomcat 7,并且我有以下球衣资源:
哪个是注册到MyApplication
( extends ResourceConfig
) 的@ApplicationPath("root")
使用 JMeter/Postman(到 /root/main/path)提交请求时,我收到不一致的 HTTP原因短语
客户不需要检查或显示原因短语。
这对于协议不是强制性的
此处列出的原因短语只是建议——它们可以被本地等效替换而不影响协议。
我从 Tomcat 7 服务器看到 200 OK 的“有效”响应:
以及来自 Tomcat 7 服务器的 200 200 的“无效”响应(相同的请求):
当我检查响应时,我没有找到任何关于更新原因短语的参考,那么这种不一致应该被忽略还是可以修复?
编辑
我的应用程序还注册了 JacksonFeature:
编辑 2
实际上我发现我在第二个环境中有额外的 jar:
常见的罐子:
编辑 3
我在 Tomcat 8.5 中发现了一个错误,它说原因短语已被删除
Christopher Schultz:我很惊讶地看到 Tomcat 主动剥离了原因短语。我最初认为这只是 Tomcat 从 Tomcat 生成的每个响应中删除原因短语(例如,来自 DefaultServlet 的所有内容、各种内部错误等),但它正在主动剥离应用程序明确设置的原因短语。
Michael Osipov:不,这不发送任何理由短语。只有 HTML 错误页面。我知道,因为我上次重写了 ErrorReportValve。
编辑 4
我找到了相关的问题,但我没有完全理解
Tomcat 8.5 从响应中删除了“HTTP 状态原因短语”,因此您将在响应中得到 HTTP 200 而不是 HTTP 200 OK。您的观察结果可能来自将状态代码复制到状态原因短语以供显示的软件。
您如何观察状态码?您可能会发现,如果您进行协议跟踪,您会看到 Tomcat/httpd 只发送了一个状态码。您确定“双重状态代码”实际上不是(正常)状态代码和恰好与状态代码相同的文本的原因短语吗?
c# - 如何将 System.Net.Http.HttpResponseMessage 转换为 System.Web.Mvc.ActionResult
我正在编写简单的代理应用程序,它获取“/xController/xMethod”之类的“URL 地址”,并通过 HttpClient 从另一个 Web 应用程序获取结果并显示结果。
我的方法:
我想在浏览器中显示我的请求,当响应是文件时,浏览器下载内容,当响应是 Json 时显示为 Json 等等。
(例如)我知道我什么时候想显示 HTML 。我在用 :
或者当我想使用 JsonActionResult 作为 html 返回或使用 FileContentResult 在文件中返回时,但我想要快速可靠的解决方案将任何 HttpResponseMessage 转换为 Best ActionResult 类
c# - HttpResponseMessage.Content 在数组中
对控制器的角度调用
我的 C# 控制器
我从一个看起来像
在帖子中返回
我将返回字符串捆绑起来并将其返回给调用角度
我在 Angular 中得到的东西看起来像这样
我怎样才能以我可以使用的字符串格式取回字符串值?
任何帮助是极大的赞赏!!
c# - HttpResponseMessage JSON
我有一个模型“数据”,其中包含一些布尔值和字符串。我希望这个模型返回一个 HttpResponseMessage。目前我正在这样做:
这会产生以下 JSON 输出"{\"\"}"
。但我需要它{""}
。HttpResponseMessage
然而,如果我只在它之前显示 JSON {""}
,我似乎不知道是什么原因导致输出格式发生变化。有谁知道这是什么原因以及如何解决这个问题?在我看来,JSON 被“字符串化”了,但为什么我不知道。
我正在使用 NewtonSoft。
c# - HttpClient 调用保持等待模式,但在控制台应用程序中工作正常
下面是当我在控制台应用程序上执行它时运行良好的代码。行
var postResponse = await client.SendAsync(req); 当我在控制台应用程序中运行代码时给出结果。
但是当我在 WebApi 控制器中使用此代码时,此代码会在此行停止。
我还比较了这两种情况下的请求对象(在控制台应用程序和 webapi 控制器调用中),但在这两种情况下,请求对象的结果都如下所示:
我不知道我做错了什么。
根据评论,我将从 apicontroller 调用的整个方法如下所示,此方法在控制台应用程序中运行良好,但是当我从 apicontroller 调用此方法时,它会继续运行。
php - PHP - 如何使用自定义响应代码发送 HTTP 响应消息?
我正在研究 REST API。并且服务器(通过 PHP 实现)有时会以自定义响应进行响应(遵循此答案的建议)。
现在,我通常通过 发送来自服务器的响应http_response_code($response_code)
,但是我也想发送带有自定义响应代码的响应消息,以便向客户端提供更多信息。我怎么做?
谢谢。