【发布时间】:2012-05-23 17:33:15
【问题描述】:
我正在尝试从 ASP.NET 和 JSP 执行 HTTP POST,但它不起作用。
我一直在阅读有关如何在 C# 中进行 HTTP POST 的文章,并且遇到了代码 sn-ps,就像我在下面使用 HttpWebRequest 编写的示例一样:
Stream stream = null;
byte[] bytes = Encoding.ASCII.GetBytes(RendercXMLForPosting(cXMLContent));
HttpWebRequest webRequest = (HttpWebRequest)WebRequest.Create(ConfigurationManager.AppSettings["Address"]);
webRequest.ContentType = "application/x-www-form-urlencoded";
webRequest.Method = "POST";
webRequest.ContentLength = bytes.Length;
webRequest.CookieContainer = new CookieContainer();
webRequest.CookieContainer.Add(new Cookie("BuyerCoookie", punchOutSession.BuyerCookieID, "/", ConfigurationManager.AppSettings["Domain"]));
try
{
stream = webRequest.GetRequestStream();
stream.Write(bytes, 0, bytes.Length);
}
catch (Exception)
{
throw;
}
finally
{
if (stream != null)
stream.Close();
}
当我尝试这个时没有抛出错误但是第 3 方站点无法识别 POST,第 3 方站点是 JSP 站点。
这是从 ASP.NET 发布到 JSP 站点的错误方式吗? 有什么我想念的吗? 提前致谢
编辑!!! 我需要在帖子完成后将用户重定向到 POST 页面,有什么帮助吗?
【问题讨论】:
-
您是否清楚 URL 必须与 JSP 的
<form action>中指定的 URL 匹配? -
那没关系。另一方显然是在滥用 JSP 而不是 servlet 来控制请求。
标签: c# jsp httpwebrequest http-post