コード例 #1
0
        public void WhenITryToPostTheHTMLToTheDomain(string httpTransactionType)
        {
            HTTPBased http = new HTTPBased();

            HTTPBased.ItemList response = new HTTPBased.ItemList();

            switch (httpTransactionType.ToLower())
            {
            case "post":
                this.context["Response"] = http.HttpPOST(
                    this.context.Keys.Any(key => key == "Domain") ? (string)this.context["Domain"] : null,
                    this.context.Keys.Any(key => key == "ResourcePath") ? (string)this.context["ResourcePath"] : null,
                    this.context.Keys.Any(key => key == "Query") ? (string)this.context["Query"] : null,
                    this.context.Keys.Any(key => key == "Header") ? (string)this.context["Header"] : null,
                    this.context.Keys.Any(key => key == "Payload") ? (string)this.context["Payload"] : null);
                break;

            case "get":
                this.context["Response"] = http.HttpGET(
                    this.context.Keys.Any(key => key == "Domain") ? (string)this.context["Domain"] : null,
                    this.context.Keys.Any(key => key == "ResourcePath") ? (string)this.context["ResourcePath"] : null,
                    this.context.Keys.Any(key => key == "Query") ? (string)this.context["Query"] : null,
                    this.context.Keys.Any(key => key == "Header") ? (string)this.context["Header"] : null,
                    this.context.Keys.Any(key => key == "Payload") ? (string)this.context["Payload"] : null);
                break;

            default:
                throw new ArgumentException($"Only supporting POST and GET.  Got [{httpTransactionType}]", "httpTransactionType");
            }

            this.context["TryException"] = http.TryException;
        }
コード例 #2
0
        public static void Example_SimpleGetUsingParameters()
        {
            // To prevent Log from output messages to Console we catch them and tell Log to not output to console.
            Log.LogOutputDelegate = LogDelegate;
            Log.LogToConsole      = false;

            // Ensure Repository has been cleared - incase any examples have changed anything...
            Repository.ClearRepositoryAll();
            HTTPBased httpRequest = new HTTPBased();

            try
            {
                HTTPBased.ItemList response = httpRequest.HttpGET("postman-echo.com", "/get", "foo=bar&alpha=7", "content-type: text/plain\r\naccept: */*\r\nhost: postman-echo.com\r\naccept-encoding: identity\r\nconnection: close\r\n");

                OutputDetails("Example of a simple HTTP GET", httpRequest, response,
                              $"Domain postman-echo.com exists and just echo's the get request in the JSON.  So we",
                              "expect the response to contain our requests arguments (foo=bar and alpha=7) in the",
                              "JSON 'args' field", "",
                              $"Note how the header line 'Content-Length: 0' has been automatically added in the.",
                              "request header.");
            }
            catch (Exception ex)
            {
                Console.WriteLine("Exception: " + ex.Message);
            }
        }