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 ...
随机推荐
- 从sample来学习Java堆(转)
1)Java堆 所有对象的实例分配都在Java堆上分配内存,堆大小由-Xmx和-Xms来调节,sample如下所示: public class HeapOOM { static class OOMOb ...
- Ubuntu 查找命令
Ubuntu 查找文件夹 使用find命令查找find / -name 文件夹名称 -type d找到结果中含有路径 查找命令 从根目录开始查找所有扩展名为.log的文本文件,并找出包含”ERROR” ...
- poj 3255 求次大最短路
Roadblocks Time Limit: 2000MS Memory Limit: 65536K Total Submissions: 5508 Accepted: 2088 Descri ...
- 【线段树】【3-21个人赛】【同样的problemB】
同一道题 http://blog.csdn.net/zy691357966/article/details/44680121 区间查询最大值 用线段树 比单调队列慢 #include <cst ...
- C#关于事件的几个好例子
#region // 定义BoiledEventArgs类,传递给Observer所感兴趣的信息 public class BoiledEventArgs : EventArgs { public r ...
- asp.net 跨页面传值常用方法
常用方法有以下: 1.queryString 2.form-post控件传递 3.cookie 4.application 5.session querystring: http://website. ...
- SQL Server插入中文数据后出现乱码
今天在做项目的过程中遇到如标题的问题,情况如下图: 数据库使用的是SQL Server2012版本,创建表的脚本如下: CREATE TABLE [dbo].[Type]( [TypeId] INT ...
- ora-00600笔记
一. ORA-600 概述 Errorsof the form ORA-600 are called internal errors. This section clarifies themisund ...
- WindowsForm 计算器
计算器 可以分一下类 数字键 + - * / % =和撤销 归零C最简单 下面看一下计算器具体的代码 using System; using System.Collections. ...
- JBOSS javax.naming.NameNotFoundException: xxx not bound
当出现JOBSS部署EJB xxx not bound 请查看ejb.jar 是否打包完全正常,是不是缺配置文件,一般是缺少配置文件或者打包不正确.