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

问题描述

我想使用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.

推荐答案


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);
    }
}


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

08-20 08:12
查看更多