繁体   English   中英

HTTP从ASP.NET发布到jsp

[英]HTTP Post from ASP.NET to jsp

我正在尝试从ASP.NET和JSP执行HTTP POST,但它无法正常工作。

我一直在阅读有关如何在C#中进行HTTP POST的文章,并且已经遇到了代码片段,就像我在下面使用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();
}

当我尝试这个没有错误被抛出,但第三方网站没有识别POST,第三方网站是一个JSP网站。

这是从ASP.NET发布到JSP站点的错误方法吗? 有什么我想念的吗? 提前致谢

编辑!!! 我需要在帖子完成后将用户重定向到POST页面,有什么帮助吗?

尝试刷新请求流,并从请求中获取响应,即:

stream = webRequest.GetRequestStream();
stream.Write(bytes, 0, bytes.Length);
stream.Flush
var rsp = webRequest.GetResponse();
using(var sr = new StreamReader(rsp.GetResponseStream())
    var result = sr.ReadToEnd(); // you might want to see what this is to debug

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM