C# 将Json字符串发布到Web Api Windows应用商店8.1

C# 将Json字符串发布到Web Api Windows应用商店8.1,c#,json,asp.net-web-api,windows-store-apps,C#,Json,Asp.net Web Api,Windows Store Apps,由于webClient已弃用且SharpRest不适用于Windows 8.1,我需要将json字符串传递给web api。 字符串js=@“[{”“用户名”“:”“杰林”“用户ID”“:”“a”“}]” var baseAddress=”http://epub3.in/sample/android%20webservice/webservice/insertuser.php/"; 这里的baseaddress是一个包含url地址的字符串。但即使我得到的IsSuccessStatusCode为t

由于webClient已弃用且SharpRest不适用于Windows 8.1,我需要将json字符串传递给web api。

字符串js=@“[{”“用户名”“:”“杰林”“用户ID”“:”“a”“}]”

var baseAddress=”http://epub3.in/sample/android%20webservice/webservice/insertuser.php/";

这里的baseaddress是一个包含url地址的字符串。但即使我得到的IsSuccessStatusCode为true,也没有输入json。
我应该在这里看到输入的结果 Android团队正在发布其参数值为

usersJSON=[{“userName”:“jerin”,“userId”:“3”}]

根据@Jon的回答,我编辑了我的代码,而不是os System.Net.Http,我现在使用的是Windows.Web.Http,但它仍然没有上传


尝试使用Windows.Web.Http命名空间中的HttpClient:

            HttpClient httpClient = new HttpClient();
            HttpRequestMessage msg = new HttpRequestMessage(new HttpMethod("POST"), new Uri(baseAddress));
            msg.Content = new HttpStringContent(js);
            msg.Content.Headers.ContentType = new HttpMediaTypeHeaderValue("application/json");
            HttpResponseMessage response = await _httpClient.SendRequestAsync(msg).AsTask();

我已经更新了我的问题。我之前的代码正在编译,感谢您提醒我应该使用Windows.Web.Http而不是System.Web.Http。你能帮我发帖吗,因为我仍然无法发帖。你做得很好,json看起来很好(带有一个项目的数组),所以它一定是服务器。确保它正在等待一个POST呼叫,而不需要任何其他标题。在android应用程序中,它已成功发布,但在Windows应用程序中未成功发布。它是否与开始时添加的usersJSON=有关?在Android代码中,
params.put(“usersJSON”,controller.composeJSONfromSQLite())
所以我认为这就是导致错误的原因。如果您还没有“Fiddler”,我如何将userJSON=也放入其中。请安装“Fiddler”,并将其用于测试请求。在“Composer”选项卡中,您可以创建POST请求,并尝试使用不同的json strings.Ty向我介绍Fiddler。是的,我认为这是web Api的问题,不是我的代码的问题。
        Windows.Web.Http.HttpClient httpClient = new Windows.Web.Http.HttpClient();
        Windows.Web.Http.HttpRequestMessage msg = new Windows.Web.Http.HttpRequestMessage(new Windows.Web.Http.HttpMethod("POST"), new Uri(baseAddress));
        msg.Content = new HttpStringContent((js));
        msg.Content.Headers.ContentType = new HttpMediaTypeHeaderValue("application/json");
        Windows.Web.Http.HttpResponseMessage response = await httpClient.SendRequestAsync(msg).AsTask();
            HttpClient httpClient = new HttpClient();
            HttpRequestMessage msg = new HttpRequestMessage(new HttpMethod("POST"), new Uri(baseAddress));
            msg.Content = new HttpStringContent(js);
            msg.Content.Headers.ContentType = new HttpMediaTypeHeaderValue("application/json");
            HttpResponseMessage response = await _httpClient.SendRequestAsync(msg).AsTask();