Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/asp.net/35.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/jsp/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
将数据从ASP.net页面发布到JSP页面_Asp.net_Jsp_Post - Fatal编程技术网

将数据从ASP.net页面发布到JSP页面

将数据从ASP.net页面发布到JSP页面,asp.net,jsp,post,Asp.net,Jsp,Post,我正在使用asp.net编写一个web应用程序。我通过一些非公共但可供服务器端使用的网络连接到JSP页面。我的目标是从asp.net页面(将是公共的)将数据发布到jsp页面(对于用户来说是私有的),然后检索jsp.net页面的答案 protected void Page_Load(object sender, EventArgs e) { Page page = HttpContext.Current.Handler as Page; String Url = "https://192.168.

我正在使用asp.net编写一个web应用程序。我通过一些非公共但可供服务器端使用的网络连接到JSP页面。我的目标是从asp.net页面(将是公共的)将数据发布到jsp页面(对于用户来说是私有的),然后检索jsp.net页面的答案

protected void Page_Load(object sender, EventArgs e)
{
Page page = HttpContext.Current.Handler as Page;
String Url = "https://192.168.0.1:1111/aaa/sss/test.jsp";
StringBuilder postData = new StringBuilder();

postData.Append("a=" + p.Request.Form[0] + "&");
postData.Append("b=" + p.Request.Form[1] + "&");
postData.Append("c=" + p.Request.Form[2] + "&");
postData.Append("d=" + p.Request.Form[3] + "&");
postData.Append("e=" + p.Request.Form[4] + "&");
postData.Append("f=" + p.Request.Form[5] + "&");
postData.Append("g=" + p.Request.Form[6] + "&");
postData.Append("h=" + p.Request.Form[7]);


StreamWriter writer = null;

HttpWebRequest request = (HttpWebRequest)WebRequest.Create(Url);
request.Method = "POST";
request.ContentType = "text/html";
request.ContentLength = postData.ToString().Length;
try
{
    writer = new StreamWriter(request.GetRequestStream());
    writer.Write(postData.ToString());
    System.Web.HttpContext.Current.Response.Write(writer.ToString());
}
finally
{
    if (writer != null)
    writer.Close();
}
}

@LuiggiMendosa但是当我检查结果时,我知道页面已经按照我说的那样工作了页面已经完成了它的工作只是我没有收到响应,我的应用程序得到了上述错误
当我更改HttpRequestHeader.ContentType时,页面不会执行任何操作

你试过什么?将此问题分为两个方面:1)ASP.NET应用程序接受用户的输入。2) 服务器端代码向外部资源发送请求。两者是分开的。您可以在.NET中使用类似于
HttpClient
的东西向外部资源发送请求并读取响应。#Luiggi Mendoza这是我使用WebClient得到的结果,您建议System.dll中出现“System.NET.WebException”类型的异常,但未在用户代码中处理其他信息:远程服务器返回一个错误:(404)找不到。@LuiggiMendoza实际上是我让它工作的。错误来自这行代码。字符串HtmlResult=wc.UploadString(Url,postData.ToString());页面已经完成了它的工作,只是我没有收到响应,我的应用程序得到了上面的错误。当我注释掉wc.Headers[HttpRequestHeader.ContentType]=“application/x-www-form-urlencoded”;--这一行,,,我没有收到任何错误,但该页没有完成其工作–远程服务器返回了一个错误:(404)未找到这意味着您访问了错误的页或该页不存在。您还应该尝试对错误消息进行一些研究。@LuiggiMendoza请阅读我的最后一条评论仅供参考,这应该作为评论发布,而不是回答。我知道,但我知道,您必须有50个声誉才能发表评论--