【问题标题】:Post data to server in windows store app在 Windows 商店应用程序中将数据发布到服务器
【发布时间】:2013-09-16 10:19:19
【问题描述】:

我想以键值对的形式将数据发送到我的网络服务。我不知道怎么做,做post的基本方法是。

HttpClient httpClient = new HttpClient();
HttpResponseMessage response = httpClient.PostAsync("http://50.16.234.220/helloapp/api/public/", new StringContent("asdad")).Result;

我的 Api 需要配对来获取数据,所以请告诉我如何在 Windows 8 应用程序中执行此操作。感谢任何帮助。

【问题讨论】:

    标签: c# .net windows-8 httpclient


    【解决方案1】:

    试试这个

    using System.Net.Http;
    
    protected async override void OnNavigatedTo(NavigationEventArgs e)
    {
        var data = new List<KeyValuePair<string, string>>
        {
            new KeyValuePair<string, string>("key_1", "value_1"),
            new KeyValuePair<string, string>("key_2", "value_1")
        };
    
        await PostKeyValueData(data);
    }
    
    private async Task PostKeyValueData(List<KeyValuePair<string, string>> values)
    {
        var httpClient = new HttpClient();
        var response = await httpClient.PostAsync("http://50.16.234.220/helloapp/api/public/", new FormUrlEncodedContent(values));
        var responseString = await response.Content.ReadAsStringAsync();
    }
    

    【讨论】:

    • 太好了。在问题中发布您的解决方案,以便其他人知道。
    • 您能否提供此代码的服务器端示例,尤其是文件上传
    • 在 W3Schools 上查看 PHP file upload
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2021-06-16
    • 2016-02-20
    • 2013-03-08
    • 1970-01-01
    • 1970-01-01
    • 2021-05-16
    相关资源
    最近更新 更多