【问题标题】:Post Form using C#使用 C# 发布表单
【发布时间】:2013-05-21 17:52:44
【问题描述】:

我需要使用 C# 将数据发布到其他网站。

<form action="http://localhost:2180/PrepDoc.aspx" method="post" target="my_frame" >
    <input type="text" name="someText" value="Some Text" />
    <input type="submit" runat="server" />
</form>
<iframe id="myIframe" name="my_frame" runat="server" >

这工作正常,但我需要使用 c# 来执行此操作。

在我尝试使用 onclick 按钮代码发布数据之前,有人可以指导我,但它需要进入我不想要的 prepdoc 页面。

HttpResponse httpResponse = HttpContext.Current.Response;
httpResponse.Clear();

httpResponse.Write("<html><head></head>");
httpResponse.Write(string.Format(
    "<body onload=\"document.{0}.submit()\">",
    "frmCart"));
httpResponse.Write(string.Format(
    "<form name=\"{0}\" method=\"{1}\" action=\"{2}\" target=\"my_frame\">", 
    "frmCart",
    "Post",
    "http://localhost:2180/PrepDoc.aspx"));
httpResponse.Write("</form>");
httpResponse.Write("</body></html>");

httpResponse.End();

我希望它出现在默认页面(调用者页面)和 iFrame 中。任何帮助将不胜感激。

【问题讨论】:

  • HTML 有必要吗?你不能只做一个 Http Post 吗?如果是这样,请查看this
  • 我想提一下 iframe 的目标,如何在 http post 中做到这一点?
  • 我不确定你的意思。你能澄清一下吗?
  • 您只是想将来自外部页面的内容包含到您现有的页面 re: iFrame 中,还是希望有一个辅助页面/表单可用于在您的主页中进行交互/发布?
  • @Pheonixblade9 我的意思是说我在 http 帖子中如果我想提及我在这里提到的目标 action="localhost:2180/PrepDoc.aspx" method="post" target="my_frame"

标签: c# forms post


【解决方案1】:

一个很好的资源是这个页面:

http://msdn.microsoft.com/en-us/library/6c3yckfw(v=vs.100).aspx

在那里你也可以找到一些代码 sn-ps。 享受。

问候 强尼

【讨论】:

    【解决方案2】:
    Source page : Session("value") = value;
    Destination page : value = Session("Value");
    

    【讨论】:

    • 请添加一些上下文来解释这个答案。
    • 无论您想发送什么到其他页面,您都可以使用该代码,例如您想发送查询结果或整数或字符串,您可以将其发送到“会话(“值”) = value;" 然后在目标页面接收它 "value = Session("Value");"
    猜你喜欢
    • 1970-01-01
    • 2020-12-15
    • 1970-01-01
    • 2014-06-17
    • 2011-05-30
    • 2016-10-06
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多