如何将经过身份验证的会话用于其他服务。 [英] how to use authenticated session for other services.

查看:86
本文介绍了如何将经过身份验证的会话用于其他服务。的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想使用vocalocity API。要使用这些服务,我需要对会话进行身份验证,然后需要使用Active session。我已登录,但不知道如何捕获所需的会话ID。



登录代码:

I want to use vocalocity API. for using the services,i need to authenticate the session and then need to use Active session.I am the logged in but not sure how to capture required session id.

Code to log in:

String url = "https://my.vocalocity.com/appserver/rest/user/null"; 
WebRequest myReq = WebRequest.Create(url); 
String username = "xxx"; 
String password = "yyy"; 
myReq.Headers.Add("login", username); 
myReq.Headers.Add("password", password); 
WebResponse wr = myReq.GetResponse(); 
Stream receiveStream = wr.GetResponseStream(); 
StreamReader reader = new StreamReader(receiveStream, Encoding.UTF8); 
string content = reader.ReadToEnd(); 



输出json


Output json

content: {
  "accountId" : xxxxx,
  "userStatusID" : 1,
  "loginName" : "xxx",
  "firstName" : "xxx",
  "lastName" : "xxx",
  "email" : "xx@xx.com",
  "phoneNumber" : "123456789",
  "role" : 0,
  "roleId" : [ 3 ],
  "secretQuestionId" : 3,
  "secretAnswer" : "shyam",
  "dateLastUpdated" : "2014-10-06T18:19:35.656Z",
  "lastUpdatedByUserId" : xxxxxx,
  "existingsuperuser" : 0,
  "contactnumbers" : [ {
    "userId" : 191716,
    "contactCode" : "D",
    "contactName" : "Default Extension",
    "contactNumber" : "329"
  } ],
  "updateMeWithAnnouncements" : 0,
  "blockAccess" : 0,
  "allowEndUserOutboundCallerId" : false,
  "userId" : xxxxxx



一旦用户通过身份验证,就会建立一个会话,会话信息将以HDAP格式返回 - ID和/或JSESSIONID cookie。调用者应该在后续请求中返回cookie以重用现有会话。



需要帮助来识别HDAP-ID和/或JSESSIONID cookie并将其捕获以供进一步使用在json内容的反序列化中。


Once the user is authenticated, a session is established and the session information will be returned in HDAP-ID and/or JSESSIONID cookies. The caller should return the cookies on subsequent requests to reuse the existing session.

Need Help in identifying HDAP-ID and/or JSESSIONID cookies and capturing the same for further use and in Deserialize of json content.

推荐答案

我不确定你是否已经找到了你的答案,但是我会接受我的所作所为。



在请求其他api调用(vonage urls)时,我会保持myReq(WebRequest)活着。基本上使用相同的对象请求其他需要首先登录的URL。

这使cookie保持在同一个会话中。



我使用WebClient而不是WebRequest,cookie(特别是HDAP-ID值)存储在webClientObj.ResponseHeaders.SetCookie

这使您可以调用其他API调用而无需获取Forbidden页面。 />


我希望这有助于某人。
I'm not sure if you already found your answer or not, but I'll chime in with what I did.

I would keep myReq (WebRequest) alive when requesting other api calls (vonage urls). Basically use the same object as you request other urls that require logging in first.
This keeps the cookie in the same session.

I use WebClient instead of WebRequest and the cookie (specifically the HDAP-ID value) is stored in webClientObj.ResponseHeaders.SetCookie
This should enable you to call the other API calls without getting the Forbidden page.

I hope this helps someone.


Vonage

http://businesssupport.vonage.com/ci/fattach/get/2776/0/filename/API+Guide+VBS+01282015。 pdf [ ^ ]



Vonage
http://businesssupport.vonage.com/ci/fattach/get/2776/0/filename/API+Guide+VBS+01282015.pdf[^]

public static void ClickToCall(string user, string password, string number)
{
    const string sAuthenticationUri = "https://my.vonagebusiness.com/appserver/rest/user/null";
    const string sClickToCallUriFormat = "https://my.vonagebusiness.com/presence/rest/clicktocall/{0}";

    string sClickToCallUri = string.Format(sClickToCallUriFormat, number);

    using (WebClient oClient = new WebClient())
    {
        oClient.Headers.Add("login", user);
        oClient.Headers.Add("password", password);

        string sAuthenticationResult = oClient.DownloadString(sAuthenticationUri);
        string sClickToCallResult = oClient.DownloadString(sClickToCallUri);
    }
}


这篇关于如何将经过身份验证的会话用于其他服务。的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆