其余Web服务.getresponse() [英] Rest web services .getresponse()
本文介绍了其余Web服务.getresponse()的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
这是代码
This is the code
private HttpWebRequest CreateWebRequest(string endPoint)
{
var request = (HttpWebRequest)WebRequest.Create(endPoint);
request.Method = "GET";
//request.ContentLength = 0;
request.ContentType = "text/xml";
return request;
}
private void btnon_Click(object sender, RoutedEventArgs e)
{
HttpWebRequest request = CreateWebRequest("GOOD WORKING URL");
using (var response = (HttpWebResponse)request.GetResponse())
{
var responseValue = string.Empty;
if (response.StatusCode != HttpStatusCode.OK)
{
string message = String.Format("POST failed. Received HTTP {0}", response.StatusCode);
throw new ApplicationException(message);
}
// grab the response
using (var responseStream = response.GetResponseStream())
{
using (var reader = new StreamReader(responseStream))
{
responseValue = reader.ReadToEnd();
}
}
return responseValue;
}
}
发生的是
What is happening is that the
(HttpWebResponse)request.GetResponse())
告诉我
Error 1 'System.Net.HttpWebRequest' does not contain a definition for 'GetResponse' and no extension method 'GetResponse' accepting a first argument of type 'System.Net.HttpWebRequest' could be found (are you missing a using directive or an assembly reference?)
我不知道为什么
有帮助吗?
I don''t know why.
Any help?
推荐答案
基于您的评论的答案-
Windows Phone 7开发基于Silvelight(我认为您没有在进行XNA编程). Silverlight是异步的,因此仅允许异步调用.
请尝试使用BeginGetResponse
.
请查看以下链接以获取更多信息.
http://msdn.microsoft.com/en-us/library/system.net.httpwebrequest%28VS.95%29.aspx
http://stackoverflow.com/questions/3849937/multiple-problems-with-httpwebresponse
Answer based on your Comments -
Windows Phone 7 Development is Silvelight based(I take you are not doing XNA Programming). Silverlight is Asynchronous and hence allows only Asynchronous calls.
Try by usingBeginGetResponse
.
Have a look at below links for more information.
http://msdn.microsoft.com/en-us/library/system.net.httpwebrequest%28VS.95%29.aspx
http://stackoverflow.com/questions/3849937/multiple-problems-with-httpwebresponse
这篇关于其余Web服务.getresponse()的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文