Can't find HttpWebRequest.GetResponse() in WP7 Project

后端 未结 1 460
礼貌的吻别
礼貌的吻别 2020-12-31 07:52

I\'m trying to send a GET request using HttpWebRequest.
I\'ve found a lot of examples all over the web (for example, this one...just go down to the Scrape()

相关标签:
1条回答
  • 2020-12-31 08:42

    XNA 4 for Windows Phone 7 can only make asynchronous calls. You might find the code at the bottom of this post helpful as well.

    Code from that post:

    protected override void Initialize()
    {
        string webServiceAddress = @"http://localhost/service/service1.asmx";           
        string methodName = "HelloWorld";
    
        string webServiceMethodUri = string.Format("{0}/{1}", webServiceAddress, methodName);
    
        HttpWebRequest httpWebRequest = (HttpWebRequest)HttpWebRequest.Create(webServiceMethodUri);
        httpWebRequest.Method = "POST";
    
        httpWebRequest.BeginGetResponse(Response_Completed, httpWebRequest);
    
        base.Initialize();
     }
    
     void Response_Completed(IAsyncResult result)
     {
        HttpWebRequest request = (HttpWebRequest)result.AsyncState;
        HttpWebResponse response = (HttpWebResponse)request.EndGetResponse(result);
    
        using (StreamReader streamReader = new StreamReader(response.GetResponseStream()))
        {
            string xml = streamReader.ReadToEnd();
    
            using(XmlReader reader = XmlReader.Create(new StringReader(xml)))
            {
                 reader.MoveToContent();
                 reader.GetAttribute(0);
                 reader.MoveToContent();
                 message = reader.ReadInnerXml();
            }
        }
     }
    
    0 讨论(0)
提交回复
热议问题