Windows Phone 8.1 中的 POST 请求

本文关键字:POST 请求 中的 Phone Windows | 更新日期: 2023-09-27 17:56:39

我想在Windows Phone 8.1中做这件事,请建议如何做。我尝试过httpclient,但没有达到相同的结果,请给我一些建议

private async void Button_Click(object sender, RoutedEventArgs e)
    {
        WebClient web = new WebClient();
        web.Headers["content-type"] = "application/x-www-form-urlencoded";
        string arg = "id=" + newone.Text;
        // var postdata =js
        string arg1 = "id=" + newone.Text;
        //web.UploadStringAsync(new Uri("http://terasol.in/hoo/test.php/?id=&ncuavfvlqfd"), "GET");
        web.UploadStringAsync(new Uri("http://terasol.in/hoo/test.php"), "POST", arg1);
        web.UploadStringCompleted += web_uploadstringcomplete;
    }
    void web_uploadstringcomplete(object sender, UploadStringCompletedEventArgs e)
    {
        MessageBox.Show(e.Result);
    }

谢谢

Windows Phone 8.1 中的 POST 请求

根据您的示例代码并运行它,使用以下代码,我得到返回的相同值。

        private static void Button_Click2(string id)
    {
        using (var client = new HttpClient())
        {
            client.BaseAddress = new Uri("http://terasol.in/");
            var content = new FormUrlEncodedContent(new[] 
        {
            new KeyValuePair<string, string>("id", id)
        });
            var result = client.PostAsync("/hoo/test.php", content).Result;
            string resultContent = result.Content.ReadAsStringAsync().Result;
            Console.WriteLine(resultContent);
        }
    }