将发布参数从Silverlight发送到子窗口

时间:2011-12-14 14:49:47

标签: http c#-4.0 post silverlight-4.0

我正在尝试在Silverlight中打开一个新窗口。我想通过HTTP Post请求发送这些参数,而不是使用查询字符串来发送一些参数。我能这样做吗? 谢谢

这就是我的尝试:

    private void GoToUrl()
    {           
        System.Net.HttpWebRequest myRequest =
        (HttpWebRequest)WebRequest.Create(Url);
        myRequest.Method = "POST";
        myRequest.ContentType = "application/x-www-form-urlencoded";
        myRequest.BeginGetRequestStream(new AsyncCallback(GetRequestStreamCallback), myRequest);
    }

    private void GetRequestStreamCallback(IAsyncResult asynchronousResult)
    {
        HttpWebRequest request = (HttpWebRequest)asynchronousResult.AsyncState;
        System.IO.Stream postStream = request.EndGetRequestStream(asynchronousResult);

        string postData = "target=" + EncryptedTarget;
        postData += ("&id=" + Id);
        byte[] byteArray = System.Text.Encoding.UTF8.GetBytes(postData);
        // Write to the request stream.
        postStream.Write(byteArray, 0, postData.Length);
        postStream.Close();            
    }
  

这似乎不再打开我的页面了。我也尝试过使用WebClient,并且也是如此。

0 个答案:

没有答案