【问题标题】:post request in windows phone 8.1在 windows phone 8.1 中发布请求
【发布时间】:2015-06-17 20:39:00
【问题描述】:

我想在 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 中一样,webclient 或相关的所有方法都不存在,所以我可以在 c# 的 8.1 手机应用程序中使用什么
  • 你试过使用HttpClient吗? msdn.microsoft.com/library/windows/apps/dn298639
  • 我尝试了但没有得到结果
  • 我想发布字符串说 string arg="id="+sometext 从 php 文件中获取响应

标签: c# windows-phone-8.1


【解决方案1】:

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

        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);
        }

    }

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2015-02-28
    • 2014-11-21
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多