[英]Cookie missing in Restsharp response but not in Postman
我能夠使用Postman並成功使用Postman使用WebAPI登錄並為以下請求獲取cookie。
我從Postman抓取代碼,然后使用RestSharp將其放在Visual Studio C#中。 但是,對於Visual Studio和RestSharp,該請求以成功成功200的形式返回,但沒有COOKIE。
我想念什么? 我已經在網上尋找了4天。
謝謝你的幫助。 以下是Postman的C#代碼:
var client = new RestClient("https://client.awebsite.ca/user/login?_format=hal_json");
var request = new RestRequest(Method.POST);
request.AddHeader("Postman-Token", "a16887c6-a1da-fa25-e721-621c4b19318b");
request.AddHeader("Cache-Control", "no-cache");
request.AddHeader("Content-Type", "text/plain");
request.AddParameter("undefined", "{\"name\":\"firstname.lastname\", \"pass\":\"passwordoffirstnamelastname\"}", ParameterType.RequestBody);
IRestResponse response = client.Execute(request);
看起來您好像沒有創建CookieContainer
。
參見: https : //github.com/restsharp/RestSharp/wiki/Cookies
var client = new RestClient("https://client.awebsite.ca/user/login?_format=hal_json");
client.CookieContainer = new System.Net.CookieContainer();
// Your request code...
IRestResponse response = client.Execute(request);
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.