当前位置: 首页>>代码示例>>C#>>正文


C# SteamClient.Execute方法代码示例

本文整理汇总了C#中SteamClient.Execute方法的典型用法代码示例。如果您正苦于以下问题:C# SteamClient.Execute方法的具体用法?C# SteamClient.Execute怎么用?C# SteamClient.Execute使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在SteamClient的用法示例。


在下文中一共展示了SteamClient.Execute方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: GET_Add_QueryString_Params

        public void GET_Add_QueryString_Params()
        {
            using( SimulatedServer.Create( AccessConstants.SimulatedServerUrl, QueryString_Echo ) ) {

                // All Params added, GetOrPost & QueryString, should be present in the result set
                SteamClient client = new SteamClient( AccessConstants.SimulatedServerUrl );
                var request = new SteamRequest( "/resource" );

                request.AddParameter( "param1", "1234", ParameterType.GetOrPost );
                request.AddParameter( "param2", "5678", ParameterType.QueryString );

                var response = client.Execute( request );

                Assert.IsNotNull( response.Content );

                string[] temp = response.Content.Split( '|' );

                NameValueCollection coll = new NameValueCollection();
                foreach( string s in temp ) {
                    var split = s.Split( '=' );
                    coll.Add( split[0], split[1] );
                }

                Assert.IsNotNull( coll["param1"] );
                Assert.AreEqual( "1234", coll["param1"] );

                Assert.IsNotNull( coll["param2"] );
                Assert.AreEqual( "5678", coll["param2"] );

            }
        }
开发者ID:chaoscode,项目名称:SteamSharp,代码行数:31,代码来源:UriBuilderTests.cs

示例2: NonExistant_Base_Returns_Error

        public void NonExistant_Base_Returns_Error()
        {
            SteamClient client = new SteamClient( "http://hopefullyth-is-domain-nev-rexists.com" );

            SteamRequest request = new SteamRequest( "/resource" );
            var response = client.Execute( request );

            Assert.AreEqual( ResponseStatus.Error, response.ResponseStatus );
        }
开发者ID:chaoscode,项目名称:SteamSharp,代码行数:9,代码来源:RequestExecution.cs

示例3: GET_GetGlobalAchievementPercentagesForApp_NoValues

        public void GET_GetGlobalAchievementPercentagesForApp_NoValues()
        {
            SteamClient client = new SteamClient();
            SteamRequest request = new SteamRequest( "ISteamUserStats/GetGlobalAchievementPercentagesForApp/v0002/" );

            var response = client.Execute( request );

            Assert.AreEqual( HttpStatusCode.BadRequest, response.StatusCode );
        }
开发者ID:chaoscode,项目名称:SteamSharp,代码行数:9,代码来源:ISteamUserStats.cs

示例4: GET_GetNewsForApp_NoValues

        public void GET_GetNewsForApp_NoValues()
        {
            SteamClient client = new SteamClient();
            SteamRequest request = new SteamRequest( "ISteamNews/GetNewsForApp/v0002/" );

            var response = client.Execute( request );

            Assert.AreEqual( HttpStatusCode.BadRequest, response.StatusCode );
        }
开发者ID:chaoscode,项目名称:SteamSharp,代码行数:9,代码来源:ISteamNews.cs

示例5: GET_GetPlayerSummaries_BadAuth

        public void GET_GetPlayerSummaries_BadAuth()
        {
            SteamClient client = new SteamClient();
            client.Authenticator = SteamSharp.Authenticators.APIKeyAuthenticator.ForProtectedResource( "8675309" );

            SteamRequest request = new SteamRequest( "ISteamUser/GetPlayerSummaries/v0002/" );
            request.AddParameter( "steamids", "76561197960435530", ParameterType.QueryString );

            var response = client.Execute( request );

            Assert.AreEqual( HttpStatusCode.Unauthorized, response.StatusCode );
        }
开发者ID:chaoscode,项目名称:SteamSharp,代码行数:12,代码来源:ISteamUser.cs

示例6: ClientContext_Request_Correctly_Times_Out

        public void ClientContext_Request_Correctly_Times_Out()
        {
            using( SimulatedServer.Create( AccessConstants.SimulatedServerUrl, Timeout_Simulator ) ) {

                SteamClient client = new SteamClient( AccessConstants.SimulatedServerUrl );
                client.Timeout = 1000;

                SteamRequest request = new SteamRequest( "/404" );
                var response = client.Execute( request );

                Assert.AreEqual( ResponseStatus.TimedOut, response.ResponseStatus );

            }
        }
开发者ID:chaoscode,项目名称:SteamSharp,代码行数:14,代码来源:RequestExecution.cs

示例7: GET_GetNewsForApp_ByUri

        public void GET_GetNewsForApp_ByUri()
        {
            SteamClient client = new SteamClient();
            SteamRequest request = new SteamRequest( "ISteamNews/GetNewsForApp/v0002/" );

            request.AddParameter( "appid", 440 );
            request.AddParameter( "count", 2 );
            request.AddParameter( "maxlength", 100 );

            var response = client.Execute( request );

            Assert.AreEqual( HttpStatusCode.OK, response.StatusCode );
            Assert.IsNotNull( response.Content );
        }
开发者ID:chaoscode,项目名称:SteamSharp,代码行数:14,代码来源:ISteamNews.cs

示例8: GET_GetNewsForApp_ByEnums

        public void GET_GetNewsForApp_ByEnums()
        {
            SteamClient client = new SteamClient();
            SteamRequest request = new SteamRequest( SteamAPIInterface.ISteamNews, "GetNewsForApp", SteamMethodVersion.v0002 );

            request.AddParameter( "appid", 440 );
            request.AddParameter( "count", 2 );
            request.AddParameter( "maxlength", 100 );

            var response = client.Execute( request );

            Assert.AreEqual( HttpStatusCode.OK, response.StatusCode );
            Assert.IsNotNull( response.Content );
        }
开发者ID:chaoscode,项目名称:SteamSharp,代码行数:14,代码来源:ISteamNews.cs

示例9: Verify_APIKey_Added

        public void Verify_APIKey_Added()
        {
            // Did you remember to add your API Token?
            Assert.IsNotNull( AccessConstants.APIKey );
            Assert.AreNotEqual( AccessConstants.APIKey, "" );

            using( SimulatedServer.Create( AccessConstants.SimulatedServerUrl, ApiKeyEchoHandler ) ) {

                var client = new SteamClient( AccessConstants.SimulatedServerUrl );

                client.Authenticator = SteamSharp.Authenticators.APIKeyAuthenticator.ForProtectedResource( AccessConstants.APIKey );

                SteamRequest request = new SteamRequest( "/resource" );
                var response = client.Execute( request );

                Assert.AreEqual( "key|" + AccessConstants.APIKey, response.Content );

            }
        }
开发者ID:chaoscode,项目名称:SteamSharp,代码行数:19,代码来源:Authenticators.cs

示例10: POST_Can_Add_Body_NoParams_Raw

        public void POST_Can_Add_Body_NoParams_Raw()
        {
            using( SimulatedServer.Create( AccessConstants.SimulatedServerUrl, Post_Body_Echo ) ) {

                SteamClient client = new SteamClient( AccessConstants.SimulatedServerUrl );
                var request = new SteamRequest( "/resource", HttpMethod.Post );
                request.DataFormat = PostDataFormat.Raw;

                string payload = "myContent 123 abc's fun!";

                request.AddBody( payload );

                var response = client.Execute( request );

                Assert.IsNotNull( response );
                Assert.IsNotNull( response.Content );
                Assert.AreEqual( payload, response.Content );

            }
        }
开发者ID:chaoscode,项目名称:SteamSharp,代码行数:20,代码来源:RequestExecution.cs

示例11: POST_Can_Add_DataStructure_Json

        public void POST_Can_Add_DataStructure_Json()
        {
            using( SimulatedServer.Create( AccessConstants.SimulatedServerUrl, Post_Body_Echo ) ) {

                SteamClient client = new SteamClient( AccessConstants.SimulatedServerUrl );
                var request = new SteamRequest( "/resource", HttpMethod.Post );
                request.DataFormat = PostDataFormat.Json;

                object payload = new {
                    appids_filter = new int[] { 10, 20, 30, 40, 50 }
                };

                request.AddBody( payload );

                var response = client.Execute( request );

                Assert.IsNotNull( response );
                Assert.IsNotNull( response.Content );

                DataStructureResponseTest obj = JsonConvert.DeserializeObject<DataStructureResponseTest>( response.Content );

                Assert.AreEqual( 5, obj.appids_filter.Length );

            }
        }
开发者ID:chaoscode,项目名称:SteamSharp,代码行数:25,代码来源:RequestExecution.cs

示例12: GetAccessTokenForUser

        /// <summary>
        /// Queries Steam API with user credentials and returns a valid access token for use in API calls.
        /// </summary>
        /// <param name="username">Username of the user requesting authentication.</param>
        /// <param name="password">Password for the user requesting authentication.</param>
        /// <param name="steamGuardAnswer"></param>
        /// <param name="captchaAnswer"></param>
        /// <returns>Access token which can then be used with the UserAuthenticator.ForProtectedResource method.</returns>
        public static SteamAccessRequestResult GetAccessTokenForUser( string username, string password, SteamGuardAnswer steamGuardAnswer = null, CaptchaAnswer captchaAnswer = null )
        {
            RSAValues publicKey = GetRSAKeyValues( username );

            // RSA Encryption
            RSAHelper rsa = new RSAHelper();
            rsa.ImportParameters( new RSAParameters {
                E = publicKey.PublicKeyExponent.HexToByteArray(),
                N = publicKey.PublicKeyModulus.HexToByteArray()
            } );

            byte[] cipherPassword = rsa.Encrypt( Encoding.UTF8.GetBytes( password ) );
            string encodedCipherPassword = Convert.ToBase64String( cipherPassword );

            SteamClient client = new SteamClient( "https://steamcommunity.com/" );
            SteamRequest request = new SteamRequest( "mobilelogin/dologin", HttpMethod.Post );

            request.AddParameter( "username", username, ParameterType.QueryString );
            request.AddParameter( "password", encodedCipherPassword, ParameterType.QueryString );
            request.AddParameter( "rsatimestamp", publicKey.Timestamp, ParameterType.QueryString );
            request.AddParameter( "oauth_client_id", "DE45CD61", ParameterType.QueryString );
            request.AddParameter( "oauth_scope", "read_profile write_profile read_client write_client", ParameterType.QueryString );

            if( captchaAnswer != null ) {
                request.AddParameter( "captchagid", captchaAnswer.GID, ParameterType.QueryString );
                request.AddParameter( "captcha_text", captchaAnswer.SolutionText, ParameterType.QueryString );
            }

            if( steamGuardAnswer != null ) {
                request.AddParameter( "emailsteamid", steamGuardAnswer.ID, ParameterType.QueryString );
                request.AddParameter( "emailauth", steamGuardAnswer.SolutionText, ParameterType.QueryString );
            }

            ISteamResponse response = client.Execute( request );
            if( !response.IsSuccessful )
                throw new SteamRequestException( "User authentication failed. Request to procure Steam access token failed (HTTP request not successful).", response ) {
                    IsRequestIssue = true
                };

            SteamTokenResult result;

            try {
                result = JsonConvert.DeserializeObject<SteamTokenResult>( response.Content );
            } catch( Exception e ) {
                throw new SteamRequestException( "Unable to deserialize the token response from Steam.", e ) {
                    IsDeserializationIssue = true
                };
            }

            if( !result.IsSuccessful ){
                return new SteamAccessRequestResult {
                    IsSuccessful = false,
                    SteamResponseMessage = result.Message,
                    IsCaptchaNeeded = result.IsCaptchaNeeded,
                    CaptchaURL = ( String.IsNullOrEmpty( result.CaptchaGID ) ) ? null : "https://steamcommunity.com/public/captcha.php?gid=" + result.CaptchaGID,
                    CaptchaGID = ( String.IsNullOrEmpty( result.CaptchaGID ) ) ? null : result.CaptchaGID,
                    IsSteamGuardNeeded = result.IsEmailAuthNeeded,
                    SteamGuardID = ( String.IsNullOrEmpty( result.EmailSteamID ) ) ? null : result.EmailSteamID,
                    SteamGuardEmailDomain = ( String.IsNullOrEmpty( result.EmailDomain ) ) ? null : result.EmailDomain
                };
            }

            if( result.OAuthParams == null )
                throw new SteamRequestException( "Login was successful did the response did not contain expected OAuth access information.", response );

            OAuthParameters oauthParams = JsonConvert.DeserializeObject<OAuthParameters>( result.OAuthParams );

            SteamUser user = new SteamUser {
                SteamID = new SteamID( oauthParams.SteamID ),
                OAuthAccessToken = oauthParams.OAuthToken
            };

            return new SteamAccessRequestResult {
                IsSuccessful = true,
                IsLoginComplete = result.IsLoginComplete,
                User = user
            };
        }
开发者ID:chaoscode,项目名称:SteamSharp,代码行数:86,代码来源:UserAuthenticator.cs

示例13: GetRSAKeyValues

        private static RSAValues GetRSAKeyValues( string username )
        {
            SteamClient client = new SteamClient( "https://steamcommunity.com/" );
            SteamRequest request = new SteamRequest( "login/getrsakey" );
            request.AddParameter( "username", username, ParameterType.QueryString );

            ISteamResponse response = client.Execute( request );

            if( !response.IsSuccessful )
                throw new SteamRequestException( "User authentication failed. Request to procure Steam RSA Key failed (HTTP request not successful).", response ) {
                    IsRequestIssue = true
                };

            RSAValues result = JsonConvert.DeserializeObject<RSAValues>( response.Content );

            if( !result.Success || String.IsNullOrEmpty( result.PublicKeyModulus ) || String.IsNullOrEmpty( result.PublicKeyExponent ) )
                throw new SteamAuthenticationException( "Unable to authenticate user. Likely the username supplied is invalid." );

            return result;
        }
开发者ID:chaoscode,项目名称:SteamSharp,代码行数:20,代码来源:UserAuthenticator.cs

示例14: GetAccessTokenForUser

        public static string GetAccessTokenForUser( SteamUser user )
        {
            SecureRandom sr = new SecureRandom();
            var sessionKey = new byte[32];
            sr.NextBytes( sessionKey );

            RSAHelper rsa = new RSAHelper();
            rsa.ImportParameters( new RSAParameters {
                N = UniversePublicKeys.GetPublicKey( SteamUniverse.Public )
            } );

            byte[] encSessionKey = rsa.Encrypt( sessionKey );

            byte[] loginKey = Encoding.UTF8.GetBytes( user.AuthCookieLoginKey );

            byte[] encLoginKey = AESHelper.Encrypt( loginKey, sessionKey );

            SteamClient client = new SteamClient( "http://api.steampowered.com/" );
            SteamRequest request = new SteamRequest( "ISteamUserAuth/AuthenticateUser/v0001", HttpMethod.Post );

            request.DataFormat = PostDataFormat.FormUrlEncoded;

            request.AddParameter( "steamid", user.SteamID.ToString(), ParameterType.GetOrPost );
            request.AddParameter( "sessionkey", StringFormat.UrlEncode( encSessionKey ), ParameterType.GetOrPost, true );
            request.AddParameter( "encrypted_loginkey", StringFormat.UrlEncode( encLoginKey ), ParameterType.GetOrPost, true );
            request.AddParameter( "format", "json", ParameterType.GetOrPost );

            var response = client.Execute( request );

            return null;
        }
开发者ID:chaoscode,项目名称:SteamSharp,代码行数:31,代码来源:AuthCookieAuthenticator.cs

示例15: GET_GetPlayerSummaries_NoValues

        public void GET_GetPlayerSummaries_NoValues()
        {
            SteamClient client = new SteamClient();
            client.Authenticator = SteamSharp.Authenticators.APIKeyAuthenticator.ForProtectedResource( AccessConstants.APIKey );

            SteamRequest request = new SteamRequest( "ISteamUser/GetPlayerSummaries/v0002/" );

            var response = client.Execute( request );

            Assert.AreEqual( HttpStatusCode.BadRequest, response.StatusCode );
        }
开发者ID:chaoscode,项目名称:SteamSharp,代码行数:11,代码来源:ISteamUser.cs


注:本文中的SteamClient.Execute方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。