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的更多相关文章

  1. 【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 ...

  2. ASP.NET Web API 安全筛选器

    原文:https://msdn.microsoft.com/zh-cn/magazine/dn781361.aspx 身份验证和授权是应用程序安全的基础.身份验证通过验证提供的凭据来确定用户身份,而授 ...

  3. web API简介(二):客户端储存之document.cookie API

    概述 前篇:web API简介(一):API,Ajax和Fetch 客户端储存从某一方面来说和动态网站差不多.动态网站是用服务端来储存数据,而客户端储存是用客户端来储存数据.document.cook ...

  4. 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 ...

  5. ASP.NET Core Web API 跨域(CORS) Cookie问题

    身为一个Web API,处理来自跨域不同源的请求,是一件十分合理的事情. 先上已有的文章,快速复制粘贴,启用CORS: Microsoft:启用 ASP.NET Core 中的跨域请求 (CORS) ...

  6. ASP.NET MVC View 和 Web API 的基本权限验证

    ASP.NET MVC 5.0已经发布一段时间了,适应了一段时间,准备把原来的MVC项目重构了一遍,先把基本权限验证这块记录一下. 环境:Windows 7 Professional SP1 + Mi ...

  7. 基于.Net Framework 4.0 Web API开发(4):ASP.NET Web APIs 基于令牌TOKEN验证的实现

    概述:  ASP.NET Web API 的好用使用过的都知道,没有复杂的配置文件,一个简单的ApiController加上需要的Action就能工作.但是在使用API的时候总会遇到跨域请求的问题, ...

  8. 使用ASP.NET Web Api构建基于REST风格的服务实战系列教程【八】——Web Api的安全性

    系列导航地址http://www.cnblogs.com/fzrain/p/3490137.html 前言 这一篇文章我们主要来探讨一下Web Api的安全性,到目前为止所有的请求都是走的Http协议 ...

  9. ASP.NET Web Api 安全性(转载)

    转载地址:http://www.cnblogs.com/fzrain/p/3552423.html 在Web Api中强制使用Https 我们可以在IIS级别配置整个Web Api来强制使用Https ...

随机推荐

  1. C 语言的可变参数表函数的设计

    在c语言中使用变长参数最常见的就是下面两个函数了: int printf(const char *format, ...); int scanf(const char *format, ...); 那 ...

  2. c++一些面试题目

    1.What is achieved by prefixing the 'static' keyword to a file-level function or file-level variable ...

  3. linux 下使用 tc 模拟网络延迟和丢包(转)

    1 模拟延迟传输简介 netem 与 tc: netem 是 Linux 2.6 及以上内核版本提供的一个网络模拟功能模块.该功能模块可以用来在性能良好的局域网中,模拟出复杂的互联网传输性能,诸如低带 ...

  4. C与C++动态分配二维数组

    C: C中使用函数malloc和free两个函数. //动态分配M*N维 int **a=(int **)malloc(sizeof(int*)*M); ;i<M;i++) a[i]=(int ...

  5. pyspark 写 logistic regression

    import random as rd import math class LogisticRegressionPySpark: def __init__(self,MaxItr=100,eps=0. ...

  6. C指针

    1,每行最大长度,处理的最大列号; preprocessor directives,preprocessor,预处理器读入源代码,根据预处理指令对其进行修改,把修改后 的源代码递交给编译器; 预处理器 ...

  7. LSH、ITQ、SKLSH图像检索实验实现(包含源码下载地址)

    原文来自我的独立blog:http://www.yuanyong.org/blog/cv/lsh-itq-sklsh-compliment 这两天寻找idea,想来思去也没想到好点的方法,于是把前段时 ...

  8. activity-alias的使用

    activity-alias是android里为了反复使用Activity而设计的. 当在Activity的onCreate()方法里,运行getIntent().getComponent().get ...

  9. hadoop结构出现后format变态

    14/07/10 18:50:47 FATAL conf.Configuration: error parsing conf file: com.sun.org                     ...

  10. Android自己定义组件系列【7】——进阶实践(4)

    上一篇<Android自己定义组件系列[6]--进阶实践(3)>中补充了关于Android中事件分发的过程知识.这一篇我们接着来分析任老师的<可下拉的PinnedHeaderExpa ...