我已经有一个使用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引擎)...我想要对此进行响应....如何实现?
最佳答案
您只需要阅读响应:
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";