UrlEncode() public static method

public static UrlEncode ( byte bytes ) : string
bytes byte
return string
示例#1
0
        private async Task <string> GetTokenFromIndus()
        {
            DP_TPEntities db     = new DP_TPEntities();
            string        uri    = "https://fastag.gitechnology.in/indusindAPI/api/Authentication/RequestToken";
            var           client = new RestClient(uri);

            client.Timeout = -1;
            var    request   = new RestRequest(Method.GET);
            string nonce     = OAuthBase.GenerateNonce();
            string timeStamp = OAuthBase.GenerateTimeStamp();
            string sig       = OAuthBase.GenerateSignature(new Uri(uri), Consumerkey, ConsumerSecret, null, null, "GET", timeStamp, nonce, OAuthBase.HMACSHA1SignatureType);

            sig = HttpUtility.UrlEncode(sig);
            string authString = String.Format(@"OAuth oauth_consumer_key=""{0}"",oauth_signature_method=""HMAC-SHA1"",oauth_timestamp=""{1}"",oauth_nonce=""{2}"",oauth_version=""1.0"",oauth_signature=""{3}""""", Consumerkey, timeStamp, nonce, sig);

            request.AddHeader("Authorization", authString);
            request.AddHeader("Connection", "Keep-Alive");
            IRestResponse response = client.Execute(request);

            Console.WriteLine(response.Content);
            TokenResponse    json = JsonConvert.DeserializeObject <TokenResponse>(response.Content);
            var              x    = json.ResponseData;// this extracts the encrypted requesttoken;
            string           s1   = EncryptionsUtility.AES_DECRYPT(x, AESkey);
            clsTokenResponse obj  = JsonConvert.DeserializeObject <clsTokenResponse>(s1);

            Console.WriteLine(obj.ResponseContent.Token);
            db.IndusInd_Token_Secrete.Add(new IndusInd_Token_Secrete()
            {
                CreateDate = DateTime.Now, Token = obj.ResponseContent.Token, TokenSecrete = obj.ResponseContent.TokenSecret
            });
            db.SaveChanges();
            return(s1);
        }
示例#2
0
        public static string getheader(string strurl, string methodtype)
        {
            string nonce     = OAuthBase.GenerateNonce();
            string timeStamp = OAuthBase.GenerateTimeStamp();

            DP_TPEntities          db        = new DP_TPEntities();
            IndusInd_Token_Secrete lastestts = db.IndusInd_Token_Secrete.ToList().LastOrDefault();

            string sig = OAuthBase.GenerateSignature(new Uri(strurl), Consumerkey, ConsumerSecret, lastestts.Token, lastestts.TokenSecrete, methodtype, timeStamp, nonce, OAuthBase.HMACSHA1SignatureType);

            sig = HttpUtility.UrlEncode(sig);
            string authString2 = String.Format(@"OAuth oauth_consumer_key=""{0}"",oauth_nonce=""{1}"",oauth_signature=""{2}"",oauth_signature_method=""HMAC-SHA1"",oauth_timestamp=""{3}"",oauth_token=""{4}"",oauth_version=""1.0""", Consumerkey, nonce, sig, timeStamp, lastestts.Token);


            return(authString2);
        }