Работя върху приложение за Windows и имам проблеми с бисквитките. Моля, обърнете внимание, че работя с Windows.Web.Http, а не със системното пространство от имена HttpClient.
API, с който работя, използва заглавка за удостоверяване за удостоверяване. По принцип след POST за влизане имам нужда от начин да върна бисквитките и след това да използвам тези бисквитки, за да изпълня последващите извиквания на API. Публикувах пример за това, което имам в момента, което успява. Виждам бисквитките в резултатния обект. Просто не съм напълно сигурен накъде да отида от тук / как да продължа. Благодаря! Някакви идеи?
using MyApi.Interfaces;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Windows.Web.Http;
using Newtonsoft.Json;
using MyApi.Models.Auth;
using MyApi.Models;
namespace MyApi
{
public class MyService
{
private const string MyBaseUrl = "http://api.my.com:3000";
private readonly HttpClient _httpClient = new HttpClient();
public async Task<SignInResponse> AttemptLogin(string username, string password)
{
if (string.IsNullOrEmpty(username) || string.IsNullOrEmpty(password))
throw new ArgumentException("Username or password is null or empty");
var uri = new Uri(string.Format("{0}/{1}", MyBaseUrl, "auth/signin"));
var authSignIn = new Models.Auth.SignInRequest();
authSignIn.Email = username;
authSignIn.Password = password;
var myObject = JsonConvert.SerializeObject(authSignIn);
// I see the headers in the result object, but I'm not
// sure the best way to a) get them out and b) shove them into
// all of the next calls
var result = await _httpClient.PostAsync(uri,
new HttpStringContent(myObject.ToString(),
Windows.Storage.Streams.UnicodeEncoding.Utf8,
"application/json"));
var content = await result.Content.ReadAsStringAsync();
var successResponse = new SignInResponse();
try
{
successResponse = JsonConvert.DeserializeObject<SignInResponse>(content);
}
catch (Exception)
{
var failResponse = JsonConvert.DeserializeObject<ErrorResponse>(content);
throw new Exception(failResponse.message);
}
return successResponse;
}
}
}
CookieContainer
в следната публикация ... stackoverflow.com/questions/12373738/ - person 3-14159265358979323846264   schedule 10.07.2015