我正在使用PRG模式来避免多个表单提交.然而,它有一个严重的缺点 - 你不能简单地echo
向用户发出确认消息(显然,用户不会看到该页面,他将被重定向到另一个页面).
这个问题的解决方案是什么?我知道其中两个,但它们似乎都不完美.
http://example.com/?msg=data-saved
.它是无国籍的,所以我认为它非常可靠.但是当用户复制链接,书签等时会产生问题.或许还有其他方法我不知道?会话和URL参数的某些组合?不知道.
你认为最好的方法是什么?哪一个缺点最少?优缺点都有什么?
error-handling session user-interface redirect post-redirect-get
我想将响应重定向到另一个URL,同时它的HTTP头中包含一些POST数据.
// Inside an ASP.NET page code behind:
Response.Redirect("http://www.example.com/?data=sent%20via%20GET");
// This will sent data to http://www.example.com via GET.
// I want to POST this data to http://www.example.com instead.
Run Code Online (Sandbox Code Playgroud)
如何在ASP.NET中执行此操作?
以下是我要处理的情况:
我们有一个WCF客户端,它与http端点和https端点一起使用,但在从http重定向(302)到https时却没有.我们有一个F5负载均衡器,它正在执行重定向和SSL功能,但据我所知,它没有对请求做任何意外的事情.重定向似乎是WCF在执行重定向后不希望提供Windows Kerberos身份验证信息的罪魁祸首.
成功调用的顺序(即没有重定向的http)如下所示:
当呼叫被重定向并失败时,它会像这样:
它类似于这个问题,但不完全相同(虽然它确实引用了"破坏WCF协议",但我没有真正的答案,我可以找到文件).如果我们关闭F5重定向规则http和https流量工作正常.WCF真的不能处理这个简单的重定向吗?有关此漏洞的解决方法或任何文档吗?
客户端配置(请注意,使用https进行测试时,我将TransportCredentialOnly更改为Transport):
<client>
<endpoint address="http://fooserver/MyService.svc/" binding="basicHttpBinding" bindingConfiguration="clientBinding" contract="Contracts.IMyService" />
</client>
<bindings>
<basicHttpBinding>
<binding name="clientBinding">
<security mode="TransportCredentialOnly">
<transport clientCredentialType="Windows" proxyCredentialType="Windows" />
</security>
</binding>
</basicHttpBinding>
Run Code Online (Sandbox Code Playgroud)
服务器配置如下所示:
<system.serviceModel>
<serviceHostingEnvironment multipleSiteBindingsEnabled="true" />
<services>
<service behaviorConfiguration="MyServiceBehavior" name="MyService">
<endpoint address="" binding="basicHttpBinding" bindingConfiguration="securedBinding" contract="Contracts.IMyService">
</endpoint>
</service>
</services>
<bindings> …
Run Code Online (Sandbox Code Playgroud) 我是OAuth的新手,我正在使用oauth2
Python上的库来完成我的工作.
目前,当我从服务器收到回调时,参数会在URL中出现:
http://mydomain/?oauth_verifier=(SOME_DATA)&oauth_token=(SOME_DATA)&oauth_callback_confirmed=true
Run Code Online (Sandbox Code Playgroud)
我不知道是否有可能到服务器以某种方式指示POST
这些参数(oauth_verifier
,oauth_token
,oauth_callback_confirmed
),以我作为一个回调,并在URL没有显示它们(作为一个GET请求)?
谢谢!
我有简单的 url 重写器:
private static void RedirectToAPI(RewriteContext context)
{
var request = context.HttpContext.Request;
if (request.Path.Value.StartsWith("/apiendpoint", StringComparison.OrdinalIgnoreCase))
{
var json = JsonConvert.SerializeObject(request.Path.Value
.Split(new char[] { '/' }, StringSplitOptions.RemoveEmptyEntries)
.Skip(1));
var response = context.HttpContext.Response;
response.Headers[HeaderNames.Location] = $"/custom";
response.StatusCode = StatusCodes.Status301MovedPermanently;
context.Result = RuleResult.EndResponse;
using (var bodyWriter = new StreamWriter(response.Body))
{
bodyWriter.Write(json);
bodyWriter.Flush();
}
}
}
Run Code Online (Sandbox Code Playgroud)
问题是,当它重定向到/custom url 时,请求有方法 GET,而这个方法需要 POST。
比如发送 GET 请求到 url /apiendpoint/first/second/third,然后 rewriter 响应重定向,相应地,下面的请求必须是 POST 方法,但现在,它是 GET。
如何更改请求方法,即在 url 重写器响应之后?
我有一个.ashx处理程序,根据处理过程,在完成处理后会重定向到成功或错误页面.处理程序在我的站点中,但成功或错误页面可能不是(这是用户可以配置的).
有没有什么方法可以将错误详细信息传递给错误页面而不将其放在查询字符串中?
我试过了:
Response.Redirect
是标头,标头会被清除Server.Transfer
,而不是Response.Redirect
,但这不适用于不在我的网站中的网址我知道我可以在查询字符串中传递数据,但在某些情况下,我需要传递的数据对于查询字符串来说可能太长了.我还有其他选择吗?
在我的JSF应用程序,我有两页,list.jsf
并且details.jsf
,每个网页有与视图范围内自己的控制器.在list.jsf
我有一个<h:commandLink>
调用动作并传递参数:
<h:commandLink value="details" action="#{listBean.goToDetails}" >
<f:param name="id" value="#{listBean.object.pk}"/></h:commandLink>
Run Code Online (Sandbox Code Playgroud)
这是bean方法:
@ManagedBean
@ViewScoped
public class ListBean {
public String goToDetails() {
// some code
return "details?faces-redirect=true";
}
}
Run Code Online (Sandbox Code Playgroud)
我在第二个bean中读取参数,如下所示:
Map<String, String> params = FacesContext.getCurrentInstance()
.getExternalContext().getRequestParameterMap();
this.setIdParam(params.get("id"));
Run Code Online (Sandbox Code Playgroud)
当我运行此代码时,该参数不会传递给第二个bean实例.但是,当我将导航更改为forward
(没有faces-redirect=true
)时,参数将被传递,我可以看到详细信息,details.jsf
但URL与当前页面不匹配.
所以我想要做的是使用带有POST参数的"jsf隐式重定向"(不是前向)(f:param).
是response.redirect始终是http GET响应吗?否则可能是POST?
通常我们可以使用条带中的ForwardResolution(路径)重定向到另一个页面,但我想重定向到另一个站点.因此,当我使用ForwardResolution时,它将被解释为
http://localhost:8080/MySiteName/<Address of the other site>
Run Code Online (Sandbox Code Playgroud)
我已阅读此链接,但如何在地址中添加参数?我想在POST方法中向该站点提交变量.是否可以在Stripes中使用动作bean?
在Pyramid中,通过GET发送请求可以通过创建URL来完成,如下所示:
@view_config(route_name="test")
def test(request):
return HTTPFound("http://test.com/redirect_to_another_test?a=1")
Run Code Online (Sandbox Code Playgroud)
但似乎HTTPFound
POST无法做到这一点,那我该怎么做呢?有没有人有这个想法?谢谢!