我有一个视图使用响应BinaryWrite方法呈现流.这在使用Beta 2的ASP.NET 4下工作正常,但在RC版本中引发了这个异常:
"HttpException","使用自定义TextWriter时,OutputStream不可用."
<%@ Page Title="" Language="C#" Inherits="System.Web.Mvc.ViewPage" %>
<%@ Import Namespace="System.IO" %>
<script runat="server">
protected void Page_Load(object sender, EventArgs e)
{
if (ViewData["Error"] == null)
{
Response.Buffer = true;
Response.Clear();
Response.ContentType = ViewData["DocType"] as string;
Response.AddHeader("content-disposition", ViewData["Disposition"] as string);
Response.CacheControl = "No-cache";
MemoryStream stream = ViewData["DocAsStream"] as MemoryStream;
Response.BinaryWrite(stream.ToArray());
Response.Flush();
Response.Close();
}
}
</script>
</script>
Run Code Online (Sandbox Code Playgroud)
视图是从客户端重定向生成的(使用Url.Action帮助程序在前一页中使用jquery替换位置调用来渲染链接).这都在iframe中.
任何人都知道为什么会这样?
我从类似的问答中读到了答案
如何在JAVA中创建异步HTTP请求?|
异步编程设计模式 |
AsyncTask Android - 设计模式和返回值
我看到很多解决方案,但没有一个真的让我满意.
倾听者的方式
捕获结果后,处理将在onResult方法中实现.
public interface GeolocationListener {
public void onResult(Address[] addresses);
public void onError(Exception e);
}
Run Code Online (Sandbox Code Playgroud)
这个解决方案并不能让我满意,因为我想在main方法中处理结果.我讨厌这个接口,因为当返回响应时,它会在onResult中处理,导致处理链,无法返回"main"方法.
servlet的方式
public class SignGuestbookServlet extends HttpServlet {
public void doPost(HttpServletRequest req, HttpServletResponse resp)
throws IOException {
// ...
resp.sendRedirect("/guestbook.jsp");
}
}
Run Code Online (Sandbox Code Playgroud)
没有公开的Java代码调用servlet.所有配置都在web.xml中完成
我想要的方式
等待这样的回复
Response a = getResponse();
// wait until the response is received, do not go further
// process
Response b = getResponse();
// wait until the response is received, do not …Run Code Online (Sandbox Code Playgroud) 我无法理解,为什么HTML/Web UI响应比WinForms/WPF/Android View/Native UI慢?
Native UI还具有样式,元素嵌套,事件,而不是Web UI的CSS,DOM,javascript事件.
事件响应时间包括:焦点更改,下拉,滚动,动画移动,动画调整大小等.
DOM树插入/替换也很慢,插入10000个字符html将在android 4.0中的谷歌浏览器中花费100毫秒,而解析其模板仅花费20毫秒(jQuery微模板).
我重新启动可能是减速事件响应的最大因素:
HTML和CSS标准的子集可能是webview应用程序开发的未来解决方案:
http://www.silexlabs.org/haxe/cocktail/
http://www.terrainformatica.com/htmlayout/
https://github.com/tombenner/nui
http://steelratstory.com/steelrat-products/wrathwebkit
http://trac.webkit.org/wiki/EFLWebKit
https://github.com/WebKitNix/webkitnix
http://qt-project.org/doc/qt-4.8/richtext-html-subset.html
http://sealedabstract.com/rants/why-mobile-web-apps-are-slow/
一堆本机UI标记语言:http: //en.wikipedia.org/wiki/User_interface_markup_language
为什么没有简化的HTML标准和简化的Webcore布局引擎来取代这些原生的UIML?
也许我们可以在kivy.org项目中实现一个子集html.
PC,android浏览器=应用程序线程+ ui线程
iOS浏览器=应用程序线程+ ui数据线程+ ui硬件线程(CoreAnimation/OpenGL ES)
在ios浏览器中,应用程序线程可以直接调用ui硬件线程.
所以我试图通过jQuery get从头响应中获取位置.我尝试使用getResponseHeader('Location')和getAllResponseHeaders(),但它们似乎都返回null.
这是我目前的代码
$(document).ready(function(){
var geturl;
geturl = $.ajax({
type: "GET",
url: 'http://searchlight.cluen.com/E5/Login.aspx?URLKey=uzr7ncj8)',
});
var locationResponse = geturl.getResponseHeader('Location');
console.log(locationResponse);
});
Run Code Online (Sandbox Code Playgroud) 我正在使用respond_with,所有内容都正确连接,以正确获取数据.我想自定义的返回json,xml以及foobar格式在干燥的方式,但我无法弄清楚如何使用有限的做:only和:include.当数据很简单时,这些都很棒,但是对于复杂的发现,它们不符合我的要求.
可以说我有一个帖子哪个has_many图像
def show
@post = Post.find params[:id]
respond_with(@post)
end
Run Code Online (Sandbox Code Playgroud)
我希望将图像包含在响应中,以便我可以这样做:
def show
@post = Post.find params[:id]
respond_with(@post, :include => :images)
end
Run Code Online (Sandbox Code Playgroud)
但我真的不想发送整个图像对象,只是网址.除此之外,我真的希望能够做到这样的事情(伪代码):
def show
@post = Post.find params[:id]
respond_with(@post, :include => { :foo => @posts.each.really_cool_method } )
end
def index
@post = Post.find params[:id]
respond_with(@post, :include => { :foo => @post.really_cool_method } )
end
Run Code Online (Sandbox Code Playgroud)
......但是一切都干了.在较旧的rails项目中,我使用XML构建器来自定义输出,但是在json,xml,html中复制它看起来不对.我不得不想象铁路专家在Rails 3中放了一些东西,我没有意识到这种行为.想法?
我正在阅读Flask关于测试的教程.那里有这样的代码:
rv = self.app.get('/')
assert 'No entries here so far' in rv.data
Run Code Online (Sandbox Code Playgroud)
我的问题是:为什么有变量叫rv?这个缩写是什么意思?
我一直在Flask源代码中寻找它,我找到了几种变量:
app_rv = app(environ, start_response)
Run Code Online (Sandbox Code Playgroud)
和
rv = run_wsgi_app(self.application, environ, buffered=buffered)
Run Code Online (Sandbox Code Playgroud)
但是,正如您所看到的,rv这里甚至可能与rv测试中的响应对象无关.
我已经能够发现"r"可能仍然用于"响应",但"v"是什么意思?
我正在尝试使用此拦截器进行身份验证:
public class CustomInterceptor implements Interceptor {
@Override
public Response intercept(Chain chain) throws IOException {
Request request = chain.request();
// try the request
Response response = chain.proceed(request);
if (response shows expired token) {
// get a new token (I use a synchronous Retrofit call)
// create a new request and modify it accordingly using the new token
Request newRequest = request.newBuilder()...build();
// retry the request
return chain.proceed(newRequest);
}
// otherwise just pass the original response on
return response;
}
Run Code Online (Sandbox Code Playgroud)
问题是我的检查(响应显示过期令牌)与状态无关,我需要检查实际响应(正文内容).因此,在检查之后,响应被"消耗"并且任何准备身体的尝试都将失败. …
我正在Flask中编写微服务,通过API互相交流.
在发出POST请求时,我可以通过Response对象返回状态代码.有没有办法可以将此函数的数据作为JSON返回?
from flask import Flask, Response
@app.route('/login', methods=['POST'])
def login():
# Set the status code
response = Response(status=200)
# How can I return a JSON in my response object as {'username': 'febin'} ?
return response
Run Code Online (Sandbox Code Playgroud) 在签署SAML响应时,还应该签名断言:
A)生成没有断言签名的响应签名.然后在生成两个签名后注入Assertion签名.
B)生成断言签名并在生成响应签名时包含它.
C)其他的东西.?
〜提前致谢!
什么是优势和劣势的每一个Response.End()和CompleteRequest()?我应该在哪里和不应该使用它们?我找了这个问题,但我没有得到正确答案.