是否可以将 POST 数据从 JSF 应用程序发送到 aspx .NET?

Is it possible to send POST data from a JSF app to aspx .NET?

在我们的 JSF 应用程序 (MyFaces Trinidad) 中,我们单击 link 将启动一个使用 aspx (http://crd-dev:1890/Timeandreviews/Login.aspx) 的应用程序 运行。由于我们已经对用户进行了身份验证,因此我们必须将用户 ID 传递给 ASPX 应用程序。他们不想在 URL 中接收这个 GET 参数,他们需要它作为 POST 数据。是否可以将其作为 POST 数据发送? 如果可能,如何发送 JSF 以及如何在 ASPX 中读取它。

我试过在 JSF(.XHTML 页面)中进行如下设置

ExternalContext ext = FacesContext.getCurrentInstance().getExternalContext();
    HttpServletRequest httpRequest = (HttpServletRequest) ext.getRequest();
    HttpSession httpSession = (HttpSession) ext.getSession(true);
    httpRequest.setAttribute("USER_HTREQ", "TST_USR");
    httpSession.setAttribute("USER_HTSES", "TST_USR");
    ext.getRequestMap().put("USER_REQMP", "TST_USR");
    try {
        ext.redirect("http://crd-dev:1890/Timeandreviews/Login.aspx");
    } catch (IOException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    }

并尝试在 aspx 中读取为 方法一:

string[] keys = Request.Form.AllKeys;
for (int i= 0; i < keys.Length; i++) 
{
   Response.Write(keys[i] + ": " + Request.Form[keys[i]] + "<br>");
}

方法二:var oSR = new StreamReader(Request.InputStream); string sContent = oSR.ReadToEnd();

但是他们两个都有效。请帮忙

既然你不仅需要post数据,还需要重定向用户,Apache HttpClient 帮不了你。

最简单的解决方案是创建一个带有隐藏输入的表单,填写它们并 post 表单。

<form method="post" id="form-id"
      action="http://crd-dev:1890/Timeandreviews/Login.aspx">
  <input type="hidden" name="input-id" id="input-id"/>
  etc.
</form>

您可以通过像这样添加 bean 来执行 Javascripts:

String script = "document.getElementById('input-id').value = 'value';"
              + "document.getElementById('form-id').submit();";
FacesContext fctx = FacesContext.getCurrentInstance();  
ExtendedRenderKitService erks =
    Service.getRenderKitService(fctx, ExtendedRenderKitService.class);
erks.addScript(fctx, script);