最初我试图找出Response.Close和Response.End之间的区别,但是在进行了更多的谷歌搜索和研究后,很明显我没有看到Byte []被发送回客户端的常见方式.我将在下面留下代码示例,但我想知道行业标准是做什么的.
Byte[] myBytes = GetReportBytes();
HttpContext.Current.Response.ClearContent();
HttpContext.Current.Response.AppendHeader("content-length", myBytes.Length.ToString());
HttpContext.Current.Response.AppendHeader("content-Disposition", "attachment;filename=" + this.ReportFileName + GetReportExtension());
HttpContext.Current.Response.ContentType = GetApplicationContentType();
HttpContext.Current.Response.BinaryWrite(myBytes);
HttpContext.Current.Response.Flush();
HttpContext.Current.Response.Close();
//CERT FIX
//HttpContext.Current.Response.End();
Run Code Online (Sandbox Code Playgroud) http://msdn.microsoft.com/en-us/library/system.web.httpresponse.aspx
如何设置body中的内容?
HTTP/1.1 400 Bad Request
Content-Type: application/json;charset=UTF-8
Cache-Control: no-store
Pragma: no-cache
{
"message":"response content example"
}
Run Code Online (Sandbox Code Playgroud) 我开发了 RestEasy Web 服务(我用于开发 Web 服务的 maven/java/tomcat)然后我得到了消息无法使用这样的内容类型。为什么我得到这样的错误,
2015-10-19 17:55:02,823 [http-nio-8080-exec-10] WARN org.jboss.resteasy.core.ExceptionHandler - failed to execute
javax.ws.rs.NotSupportedException: Cannot consume content type
at org.jboss.resteasy.core.registry.SegmentNode.match(SegmentNode.java:380)
at org.jboss.resteasy.core.registry.SegmentNode.match(SegmentNode.java:114)
at org.jboss.resteasy.core.registry.RootNode.match(RootNode.java:43)
at org.jboss.resteasy.core.registry.RootClassNode.match(RootClassNode.java:48)
at org.jboss.resteasy.core.ResourceMethodRegistry.getResourceInvoker(ResourceMethodRegistry.java:444)
at org.jboss.resteasy.core.SynchronousDispatcher.getInvoker(SynchronousDispatcher.java:234)
at org.jboss.resteasy.core.SynchronousDispatcher.invoke(SynchronousDispatcher.java:171)
at org.jboss.resteasy.plugins.server.servlet.ServletContainerDispatcher.service(ServletContainerDispatcher.java:220)
at org.jboss.resteasy.plugins.server.servlet.HttpServletDispatcher.service(HttpServletDispatcher.java:56)
at org.jboss.resteasy.plugins.server.servlet.HttpServletDispatcher.service(HttpServletDispatcher.java:51)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:729)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:291)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
at org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:52)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:239)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:219)
at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:106)
at org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:502)
at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:142)
at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:79)
at org.apache.catalina.valves.AbstractAccessLogValve.invoke(AbstractAccessLogValve.java:616)
at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:88)
at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:518)
at org.apache.coyote.http11.AbstractHttp11Processor.process(AbstractHttp11Processor.java:1091)
at org.apache.coyote.AbstractProtocol$AbstractConnectionHandler.process(AbstractProtocol.java:673)
at org.apache.tomcat.util.net.NioEndpoint$SocketProcessor.doRun(NioEndpoint.java:1526)
at org.apache.tomcat.util.net.NioEndpoint$SocketProcessor.run(NioEndpoint.java:1482)
at …Run Code Online (Sandbox Code Playgroud) 在我的Django项目中,我需要在我的视图中将一些数据发送/发布到第三方URL,并重定向到它提供的网页.例如,我可以简单地做一些事情
class TestView(TemplateView):
def get(self, request, *args, **kwargs):
data = {
'order_id': 88888,
'subject': 'haha',
'rn_check': 'F',
'app_pay': 'T',
}
url = 'http://some-third-party-api-url?order_id=88888&subject=haha&...'
return HttpResponseRedirect(url)
Run Code Online (Sandbox Code Playgroud)
但是我想将这个第三方api用作包装的SDK,比如
class TestView(TemplateView):
def get(self, request, *args, **kwargs):
from sucre.alipay_sdk.base import Alipay
from sucre.alipay_sdk import alipay_config
from django.http import HttpResponse
alipay = Alipay(alipay_config)
data = {
'order_id': 88888,
'subject': 'haha',
'rn_check': 'F',
'app_pay': 'T',
}
'''alipay api is wrapped in a sdk'''
'''and return a requests.models.Response instance'''
result = alipay.api('pay', data)
return HttpResponse(result)
Run Code Online (Sandbox Code Playgroud)
和api代码:
def …Run Code Online (Sandbox Code Playgroud) Been looking to achieve this few months now but now it's needed. I need to display the error message, set on server, about what went wrong:
Sever endpoint
abort(406, 'Foo bar!')
Run Code Online (Sandbox Code Playgroud)
Web:
[...]
.catch(e => {
console.log(e.response.data) // does not work
})
Run Code Online (Sandbox Code Playgroud)
In chrome dev tools, under preview, I see the message Foo bar!. How to get this message on my console log?
This endpoint will have different abort messages based on actions so I do not want to …
我现在正在做的是导致:
java.io.IOException: stream is closed
Run Code Online (Sandbox Code Playgroud)
在第二个readEntity(),因为它在第一次读取后关闭流.
这是我正在做的事情:
Response response = target.queryParam("start", startIndex)
.queryParam("end", end)
.request()
.accept(MediaType.APPLICATION_XML)
.header(authorizationHeaderName, authorizationHeaderValue)
.get();
String xml = response.readEntity(String.class);
ourLogger.debug(xml);
MyClass message = response.readEntity(MyClass.class); //throws IOException
Run Code Online (Sandbox Code Playgroud) 我有无服务器 API,它与无服务器框架版本 1.25 一起使用
\n\n出于安全原因,我想添加响应标头。请帮助我如何通过 serverless.yml 文件设置以下标头。出于安全原因是否有必要添加此标头?
\n\n\xe2\x80\xa2 内容安全策略:包括 default-src 'self'
\n\n\xe2\x80\xa2 严格传输安全 max-age=31536000; 包括子域;预载
\n\n\xe2\x80\xa2 X-内容类型选项:nosniff
\n\n\xe2\x80\xa2 X-XSS 保护:1
\n\n\xe2\x80\xa2 缓存控制:max-age=0;过期=-1 或过期:1990 年 1 月 1 日星期五 00:00:00 GMT;无缓存,必须重新验证
\n\n下面是我的无服务器应用程序 serverless.yaml
\n\nservice: myService\nprovider:\n name: aws\n runtime: nodejs6.10\n stage: dev\n region: eu-west-1\n environment:\n REGION: ${self:provider.region}\n PROJECT_NAME: ${self:custom.projectName}\n SERVERLESS_STAGE: ${self:provider.stage}\n SERVERLESS_SERVICE: ${self:service}\n IP_ADDRESS: http://example.com\nfunctions:\n getMyFunction:\n handler: handler.getMyFunction\n timeout: 30\n events:\n - http:\n method: get\n path: api/getMyFunction/v1\n integration: lambda\n cors: true\n authorizer:\n name: authorizerFunc\n …Run Code Online (Sandbox Code Playgroud) javascript httpresponse amazon-web-services http-headers serverless-framework
浏览HTTP 响应代码.. 并了解这些响应代码(rcodes)代表什么
但我不确定在下面的情况下将向客户端/消费者(例如浏览器)发送什么 rcode。我使用 NGINX 作为反向代理,使用 Apache 作为 HTTP 服务器,在 NGINX 后面运行 Web 应用程序(例如应用程序)。
几个场景
应用程序中发生运行时错误,抛出 rcode 为 500(默认情况下运行时错误代码)。我的理解是nginx会继续抛出500而不将其转换为502?
应用程序已关闭或不可用。我的理解是 nginx 在这种情况下会抛出 503 而不是 502 ?
应用程序花费的时间比 nginx 默认连接超时时间还要长。我的理解是nginx在这种情况下会抛出504?
如果以上所有点都正确,不确定 nginx 何时会抛出 502 ?NGINX何时会认为从上游服务器收到的响应为无效响应?
web-applications nginx httpresponse http-response-codes nginx-reverse-proxy
我正在尝试与 Aws ApiGateway 实现 Lambda 集成,我可以使用请求映射模板解析输入,但无法使用响应映射模板脚本返回正确的 json 对象。每次我检查 api 网关日志时都会出现“由于配置错误而导致执行失败:无法转换响应”并且 api 网关返回 500 错误
lambda 返回此消息
{
"statusCode": 200,
"body": "{\"name\":\"dummy\",\"surname\":\"dummy\"}"}
Run Code Online (Sandbox Code Playgroud)
但我有响应映射模板,我试图返回
{"name":"dummy","surname":"dummy"}
Run Code Online (Sandbox Code Playgroud)
我的响应映射 vtl 脚本就像这样,没有将其分配到某个地方
$util.parseJson($input.json('$'))
Run Code Online (Sandbox Code Playgroud)
并且也尝试过
$util.parseJson($input.json('$.body'))
Run Code Online (Sandbox Code Playgroud) http httpresponse amazon-web-services aws-lambda aws-api-gateway
我正在使用静态 URL 查询数据服务。服务器(也是节点)发送大约 955k 的 JSON 数据。
1)我可以CURL数据以获得正确的结果,即它通过JSON.parse()。
2)从节点,我可以 exec("curl ..."); 并且也得到正确的结果。
3)同时使用Request和Axios,我得到了大约600k的数据。精确的字符数每次都会发生变化。
4)使用 Axios,我将数据流式传输到文件中,并获得许多“数据”事件,并将它们连接到文件中。这也是不正确的。
5)它可以在较小的有效载荷下正常工作。
专家联合起来!!我任由你摆布。我将祈求并赞扬并感谢您的帮助。
如果没有您的帮助,我将拥有一个使用 NodeJS 中的 CURL 的生产应用程序,邪恶将会获胜。
此致, TQ White II
更新:有人要求我提供代码片段。这里是:
const datGetterWORKS_FOR_SMALL_DATA_LOADS=(element, next)=>{
const localCallback=sendToTransformerCallback(element, next);
const {url, headers}=networkSpecs.connection;
axios.get(url + element.urlSegment, {
method: 'get',
responseType: 'json',
headers: headers,
maxContentLength: 6000000,
})
.then(function (response) {
localCallback('', response, response.data)
});
}
Run Code Online (Sandbox Code Playgroud)
请注意,这是给 require('async').each() 进程的。
httpresponse ×10
axios ×2
c# ×2
java ×2
javascript ×2
ajax ×1
asp.net ×1
aws-lambda ×1
class ×1
content-type ×1
django ×1
download ×1
http ×1
http-get ×1
http-headers ×1
jax-rs ×1
jaxb ×1
maven ×1
nginx ×1
node.js ×1
python ×1
response ×1
rest ×1
resteasy ×1