POST Requests

JumpKick.HttpLib — POST Requests

1. Overview of Available Request Methods (Http Static Class)

// All methods return a RequestBuilder fluent object
Http.Get(url);
Http.Post(url);
Http.Put(url);
Http.Delete(url);
Http.Patch(url);
Http.Head(url);Code language: JavaScript (javascript)

Unified fluent structure: RequestMethod().ParameterConfig().OnSuccess().OnFail().Go();

2. Two Parameter‑Passing Modes for POST

  1. .Form(): Form submission Content‑Type: application/x‑www‑form‑urlencoded (web‑form format)
  2. .Body(): Raw payload for custom JSON / XML / SOAP messages

3. Example 1: Form Submission

using System;
using JumpKick.HttpLib;

class Program
{
    static void Main(string[] args)
    {
        Http.Post("https://httpbin.org/post")
        .Form(new
        {
            name = "James",
            username = "j6mes"
        })
        .OnSuccess(result =>
        {
            Console.WriteLine("==== POST Form Request Succeeded ====");
            Console.WriteLine(result);
        })
        .OnFail(webexception =>
        {
            Console.WriteLine("==== Request Exception ====");
            Console.WriteLine(webexception.Message);
        })
        .Go();

        Console.ReadKey();
    }
}Code language: JavaScript (javascript)

4. Example 2: Submit JSON via Body

using System;
using JumpKick.HttpLib;

class Program
{
    static void Main(string[] args)
    {
        string jsonStr = "{\"account\":\"test\",\"pwd\":\"123456\"}";

        Http.Post("https://httpbin.org/post")
        .Body(jsonStr, "application/json") // Payload content + media‑type specification
        .OnSuccess(result =>
        {
            Console.WriteLine("==== POST‑JSON Request Succeeded ====");
            Console.WriteLine(result);
        })
        .OnFail(webexception =>
        {
            Console.WriteLine("==== Request Exception ====");
            Console.WriteLine(webexception.Message);
        })
        .Go();

        Console.ReadKey();
    }
}Code language: JavaScript (javascript)

5. Example 3: Handling a Failed POST

Intentionally target an endpoint that rejects POST to catch 405 and verify OnFail triggers

using System;
using JumpKick.HttpLib;

class Program
{
    static void Main(string[] args)
    {
        // httpbin.org/get only accepts GET; POST yields status 405
        Http.Post("https://httpbin.org/get")
        .Form(new
        {
            test = "demo"
        })
        .OnSuccess(result =>
        {
            Console.WriteLine("==== Request Succeeded ====");
            Console.WriteLine(result);
        })
        .OnFail(webexception =>
        {
            Console.WriteLine("==== Request Exception (405 caught) ====");
            Console.WriteLine(webexception.Message);
        })
        .Go();

        Console.ReadKey();
    }
}Code language: JavaScript (javascript)

6. Common Error Interpretation

Error: The remote server returned an error: (405) Method Not Allowed.

Cause: The target endpoint accepts GET only and rejects POST.


Solutions:

  1. Switch to a POST‑capable test endpoint (httpbin.org/post recommended)
  2. Verify allowed HTTP methods for your target API

7. GET / POST Key Comparison Summary

MethodFunctionParameter StyleTypical Use‑Case
GETHttp.Get()URL query parametersData querying
POST FormHttp.Post().Form()Form key‑value pairsWeb login, form submission
POST JSONHttp.Post().Body()Raw string payloadBackend‑frontend API communication

POST Requests

Previous:

Leave a Reply

Your email address will not be published. Required fields are marked *