如何从c#windows窗体连接java servlet?

时间:2013-01-28 04:51:40

标签: c# java google-app-engine servlets

我已经在应用程序引擎中使用java实现了一个现有的应用程序....现在我想从c#forms程序连接这个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)......我想要对此做出回应....如何实现?

1 个答案:

答案 0 :(得分:1)

您只需阅读回复:

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";