如何从 C# Windows 窗体连接 Java Servlet

本文关键字:连接 Java Servlet 窗体 Windows | 更新日期: 2023-09-27 17:56:11

我已经在应用程序引擎中使用java实现了现有的应用程序。现在我想从 C# 窗体程序连接这个 servlet?,...这是请求的试用代码

HttpWebRequest authRequest = (HttpWebRequest)HttpWebRequest.Create(googleLoginUrl);
byte[] buffer = Encoding.ASCII.GetBytes(postData);
authRequest.ContentLength = buffer.Length;
 Stream postDataStr=authRequest.GetRequestStream();
postDataStr.Write(buffer, 0, buffer.Length);
postDataStr.Close();

现在它连接到GSE(Google Servlet Engine)...我想要对此做出回应....如何实现?

如何从 C# Windows 窗体连接 Java Servlet

您只需要阅读响应:

HttpWebResponse response = (HttpWebResponse)authRequest.GetResponse ();
Console.WriteLine ("Content length is {0}", response.ContentLength);
Console.WriteLine ("Content type is {0}", response.ContentType);
string raw_html = (new StreamReader(response.GetResponseStream()).ReadToEnd();

您可以在以下位置查看更多示例: http://msdn.microsoft.com/en-us/library/system.net.httpwebrequest.getresponse.aspx

注意:我相信既然您正在发布数据,您还必须通过以下方式将authRequest设置为 POST:

authRequest.Method = "POST";