restsharp 登录后再获取数据,保持登录状态

2019/10/30 22:26
阅读数 63

 

private static RestResponseCookie prelogin()
        {
            var client = new RestClient("http://xxxx.com/callback?client_name=client");
            var request = new RestRequest(Method.POST);
            request.AddHeader("postman-token", "f66daf18-48bc-648c-f888-0787b62ee312");
            request.AddHeader("cache-control", "no-cache");
            request.AddHeader("content-type", "application/x-www-form-urlencoded");
            request.AddParameter("application/x-www-form-urlencoded", "client_name=FormClient&username=xxx&password=xxx", ParameterType.RequestBody);
            IRestResponse response = client.Execute(request);
            //PLAY_SESSION
            return response.Cookies[0];
        }




private static string getdata(RestResponseCookie loginCookie)
        {
            var client = new RestClient("http://xxx.com/getdata");

            var request = new RestRequest(Method.POST);

            request.AddCookie(loginCookie.Name,loginCookie.Value);

            request.AddHeader("postman-token", "4722e24d-1bee-9078-69ff-bbe3f05e6db3");
            request.AddHeader("cache-control", "no-cache");
            request.AddHeader("content-type", "application/json;charset=UTF-8");
            request.AddParameter("application/json;charset=UTF-8", "{\"pcode\":\"00000005\"}", ParameterType.RequestBody);

            IRestResponse response = client.Execute(request);
            return response.Content;
        }

  

展开阅读全文
打赏
0
0 收藏
分享
加载中
更多评论
打赏
0 评论
0 收藏
0
分享
返回顶部
顶部