Web API Login with Cookie
public HttpWebResponse InitiliazeWebRequest()
{
string responseData =string.Empty;//string url = GetServerEndPoint();string loginInstance ="url + logincreds";HttpWebRequest request =(HttpWebRequest)WebRequest.Create(loginInstance);
request.Method="POST";
request.ContentType="application/json";
request.CookieContainer=newCookieContainer();
HttpWebResponse response =(HttpWebResponse)request.GetResponseAsync().Result;
if(response.StatusCode==HttpStatusCode.OK)
{
using(System.IO.StreamReader responseReader =newSystem.IO.StreamReader(request.GetResponse().GetResponseStream()))
{
responseData = responseReader.ReadToEnd();
}
var toke = response.Headers.Get("authToken");
JObject o =JObject.Parse(responseData);
_authToken =(string)o["response"]["authToken"].ToString();
return response;
}
return response;
}
public HttpWebResponse LogOut(string shouldI)
{
string responseData =string.Empty;
string loginInstance ="https://www.example.com/logout";
HttpWebRequest request =(HttpWebRequest)WebRequest.Create(loginInstance);
request.Method="GET";
request.ContentType="application/json";
request.Headers.Add("Cookie: authToken="+ _authToken);
HttpWebResponse response =(HttpWebResponse)request.GetResponseAsync().Result;
if(response.StatusCode==HttpStatusCode.OK)
{
using(System.IO.StreamReader responseReader =newSystem.IO.StreamReader(request.GetResponse().GetResponseStream()))
{
responseData = responseReader.ReadToEnd();
}
return response;
}
return response;
}
Web API Login with Cookie的更多相关文章
- 【ASP.NET Web API教程】5.5 ASP.NET Web API中的HTTP Cookie
原文:[ASP.NET Web API教程]5.5 ASP.NET Web API中的HTTP Cookie 5.5 HTTP Cookies in ASP.NET Web API 5.5 ASP.N ...
- ASP.NET Web API 安全筛选器
原文:https://msdn.microsoft.com/zh-cn/magazine/dn781361.aspx 身份验证和授权是应用程序安全的基础.身份验证通过验证提供的凭据来确定用户身份,而授 ...
- web API简介(二):客户端储存之document.cookie API
概述 前篇:web API简介(一):API,Ajax和Fetch 客户端储存从某一方面来说和动态网站差不多.动态网站是用服务端来储存数据,而客户端储存是用客户端来储存数据.document.cook ...
- Secure a Web API with Individual Accounts and Local Login in ASP.NET Web API 2.2
https://docs.microsoft.com/en-us/aspnet/web-api/overview/security/individual-accounts-in-web-api Ind ...
- ASP.NET Core Web API 跨域(CORS) Cookie问题
身为一个Web API,处理来自跨域不同源的请求,是一件十分合理的事情. 先上已有的文章,快速复制粘贴,启用CORS: Microsoft:启用 ASP.NET Core 中的跨域请求 (CORS) ...
- ASP.NET MVC View 和 Web API 的基本权限验证
ASP.NET MVC 5.0已经发布一段时间了,适应了一段时间,准备把原来的MVC项目重构了一遍,先把基本权限验证这块记录一下. 环境:Windows 7 Professional SP1 + Mi ...
- 基于.Net Framework 4.0 Web API开发(4):ASP.NET Web APIs 基于令牌TOKEN验证的实现
概述: ASP.NET Web API 的好用使用过的都知道,没有复杂的配置文件,一个简单的ApiController加上需要的Action就能工作.但是在使用API的时候总会遇到跨域请求的问题, ...
- 使用ASP.NET Web Api构建基于REST风格的服务实战系列教程【八】——Web Api的安全性
系列导航地址http://www.cnblogs.com/fzrain/p/3490137.html 前言 这一篇文章我们主要来探讨一下Web Api的安全性,到目前为止所有的请求都是走的Http协议 ...
- ASP.NET Web Api 安全性(转载)
转载地址:http://www.cnblogs.com/fzrain/p/3552423.html 在Web Api中强制使用Https 我们可以在IIS级别配置整个Web Api来强制使用Https ...
随机推荐
- Mysql explain 查看分区表
mysql> explain select * from ClientActionTrack where startTime>'2016-08-25 00:00:00' and start ...
- cf459A Pashmak and Garden
A. Pashmak and Garden time limit per test 1 second memory limit per test 256 megabytes input standar ...
- OpenSuSE查看指定软件包是否安装(OpenSuSE使用RPM作为默认的软件包维护管理工具)
suse 是 zypper se xxxxx 是搜索软件包 (查看已经安装的 软件包是否已经安装)
- exit()与_exit()的区别
从图中可以看出,_exit 函数的作用是:直接使进程停止运行,清除其使用的内存空间,并清除其在内核的各种数据结构:exit 函数则在这些基础上做了一些小动作,在执行退出之前还加了若干道工序.exit( ...
- Java面试题之八
四十一.面向对象的特征有哪些方面 四大特征大家都知道:抽象.继承.封装.多态.这是个理解性表述题,每个人的表述方式可能都不一样.下面仅选择一种作为参考: 1.抽象: 抽象——就是忽略一个主题中与当前目 ...
- DoNet开源项目-基于Amaze UI的点餐系统
帮朋友做的点餐系统,主要是为了让顾客在餐桌上,使用微信扫描二维码,就可以直接点菜,吃完使用微信付款. 系统演示地址,账户名和密码均为:admin.(请不要删除admin用户) GitHub Clone ...
- Jquery库自带的动画效果方法记录
1.显示和隐藏hide()和show() <script type="text/javascript"> $(function() { ...
- 经典 SQL
经典sql 总结一些经常用到或碰到的SQL语句,希望能与大家分享,同时也希望大家能提供更多的精妙SQL语句..... 1.delete table1 from (select * from tab ...
- 读书笔记-实用单元测试(英文版) Pragmatic Unit Testing in C# with NUnit
读书笔记-实用单元测试(英文版) Pragmatic Unit Testing in C# with NUnit Author: Andrew Hunt ,David Thomas with Matt ...
- C语言预处理指令
C程序的源代码中可包括各种编译指令,这些指令称为预处理命令.虽然它们实际上不是C语言的一部分,但却扩展了C程序设计的环境.本节将介绍如何应用预处理程序和注释简化程序开发过程,并提高程序的可读性.ANS ...