private string GetHmac256(PusherRequest request) { var data = String.Format("POST\n{0}\n{1}", GetBaseUri(request), GetQueryString(request)); var hmacsha256 = new HMACSHA256(Encoding.UTF8.GetBytes(_applicationSecret)); var hash = hmacsha256.ComputeHash(Encoding.UTF8.GetBytes(data)); return(BytesToHex(hash)); }
private string GetQueryString(PusherRequest request) { var output = String.Format("auth_key={0}&auth_timestamp={1}&auth_version=1.0&body_md5={2}&name={3}", _applicationKey, (int)((DateTime.UtcNow - new DateTime(1970, 1, 1)).TotalSeconds), GetMd5Hash(request.JsonData), request.EventName); return(String.IsNullOrEmpty(request.SocketId) ? output : String.Format("{0}&socket_id={1}", output, request.SocketId)); }
/// <summary> /// Sends the request. Will throw a WebException if anything other than a 202 response is encountered /// </summary> /// <param name="request"></param> public void Trigger(PusherRequest request) { var requestUrl = String.Format("http://{0}{1}?{2}&auth_signature={3}", _host, GetBaseUri(request), GetQueryString(request), GetHmac256(request)); using(var client = new WebClient()) { client.Encoding = Encoding.UTF8; client.UploadString(requestUrl, request.JsonData); } }
/// <summary> /// Sends the request. Will throw a WebException if anything other than a 202 response is encountered /// </summary> /// <param name="request"></param> public void Trigger(PusherRequest request) { var requestUrl = String.Format("http://{0}{1}?{2}&auth_signature={3}", _host, GetBaseUri(request), GetQueryString(request), GetHmac256(request)); using (var client = new WebClient()) { if (_webProxy != null) { client.Proxy = _webProxy; } client.Encoding = Encoding.UTF8; client.UploadString(requestUrl, request.JsonData); } }
private string GetHmac256(PusherRequest request) { var data = String.Format("POST\n{0}\n{1}", GetBaseUri(request), GetQueryString(request)); var hmacsha256 = new HMACSHA256(Encoding.UTF8.GetBytes(_applicationSecret)); var hash = hmacsha256.ComputeHash(Encoding.UTF8.GetBytes(data)); return BytesToHex(hash); }
private string GetBaseUri(PusherRequest request) { return String.Format("/apps/{0}/channels/{1}/events", _applicationId, request.ChannelName); }
private string GetQueryString(PusherRequest request) { var output = String.Format("auth_key={0}&auth_timestamp={1}&auth_version=1.0&body_md5={2}&name={3}", _applicationKey, (int)((DateTime.UtcNow - new DateTime(1970,1,1)).TotalSeconds), GetMd5Hash(request.JsonData), request.EventName); return String.IsNullOrEmpty(request.SocketId) ? output : String.Format("{0}&socket_id={1}", output, request.SocketId); }
private string GetBaseUri(PusherRequest request) { return(String.Format("/apps/{0}/channels/{1}/events", _applicationId, request.ChannelName)); }