C# 如何从WinRT/Store应用程序调用webapi rest服务

C# 如何从WinRT/Store应用程序调用webapi rest服务,c#,asp.net-web-api,windows-runtime,windows-store-apps,webservice-client,C#,Asp.net Web Api,Windows Runtime,Windows Store Apps,Webservice Client,我有一个简单的要求:我需要安全地访问restfull Webapi,该API接收一些数据进行登录,然后返回一些数据: public class CredentialsModel { public string User { get; set; } public string Password { get; set; } public string ExchangeRoomId {get; set; } } 我必须发送一些数据: public class

我有一个简单的要求:我需要安全地访问restfull Webapi,该API接收一些数据进行登录,然后返回一些数据:

public class CredentialsModel
{
    public string User { get; set; }
    public string Password { get; set; }
            public string ExchangeRoomId {get; set; }
}
我必须发送一些数据:

public class CredentialsModel
{
    public string User { get; set; }
    public string Password { get; set; }
            public string ExchangeRoomId {get; set; }
}
我还想要一份预约名单:

public class Appointment
{
    public Guid AppointmentId { get; set; }
    public string AppointmentExchangeId { get; set; }

    public string Description { get; set; }

    public DateTime Start { get; set; }
    public DateTime End { get; set; }

    public TimeZoneInfo TimeZone { get; set; }
}
如何在Windows 8.1应用商店/WinRT应用程序中执行此操作?

尝试以下方法:

    using (var httpFilter = new HttpBaseProtocolFilter())
    {
        using (var httpClient = new HttpClient(httpFilter))
        {
            Uri requestUri = new Uri("");
            string json = await JsonConvert.SerializeObjectAsync(CredentialsModel);
            var response = await httpClient.PostAsync(requestUri, new HttpStringContent(json, UnicodeEncoding.Utf8, "application/json"));
            if (response.StatusCode == HttpStatusCode.Ok)
            {
                var responseAsString = await response.Content.ReadAsStringAsync();
                var deserializedResponse = await JsonConvert.DeserializeObjectAsync<IEnumerable<Appointment>>(responseAsString);
            }
        }
    }
使用(var httpFilter=new HttpBaseProtocolFilter())
{
使用(var-httpClient=new-httpClient(httpFilter))
{
Uri requestUri=新Uri(“”);
string json=await JsonConvert.SerializeObjectAsync(CredentialsModel);
var response=wait httpClient.PostAsync(requestUri,新的HttpStringContent(json,unicodeincoding.Utf8,“application/json”);
if(response.StatusCode==HttpStatusCode.Ok)
{
var responseAsString=await response.Content.ReadAsStringAsync();

var deserializedResponse=await JsonConvert.DeserializeObjectAsync我已经搜索了很多示例。但是大多数示例都是关于WCF的,或者只是一个GET或POST,但没有返回一些数据。其他示例是关于.NET framework的,但是WinRT只是.NET的一个子集,所以代码也不起作用。Trief PostAsync,但是我无法反序列化有效负载。你呢节省了我一天的时间(实际上是:天)。工作正常,谢谢。(顺便说一句:我遗漏了httpfilter,因为编译器对此表示不满)