Get the App
SLTechnology News&Howtos  ›  Internet Technology  › 

How to call API in batch in shell script

Shulou Source: shulou.com Published: 2022-06-02 09:41:34 10月29日 Update

Today, I will talk to you about how to call the interface in batches in the shell script, which may not be well understood by many people. In order to make you understand better, the editor has summarized the following for you. I hope you can get something according to this article.

The script is as follows:

#! / bin/bash

Aplasy 0

While [$a-le 10]; do

# length of ts is 13 required,Through the following way like this

Ts= `date +% s% N`

Ts=$ {ts:0:13}

Json=' {"name": "'$1$ a'", "age":'$2 million, "" ts ":'$ts'}'

Axiom $((aqui1))

Curl-k-H 'Content-Type:application/json;charset=utf-8' http://192.168.2.5:8080-X POST-d "' $json'"

Done

Batch curl script

Execute script

Sh batch_curl.sh gege 21

Execution result

Results of 10 curl execution

This API is a demo interface provided in go language:

Directory structure:

Directory structure

App.conf

Copyrequestbody = true

Controller.go

Package controller

Import (

"github.com/astaxie/beego"

"fmt"

)

Type SayHelloController struct {

Beego.Controller

}

Func (this * SayHelloController) SayHello () {

Fmt.Println ("RequestBody is", string (this.Ctx.Input.RequestBody))

This.Ctx.Output.Header ("Content-type", "application/json;charset=utf-8")

This.Ctx.Output.SetStatus (200)

This.Ctx.Output.Body (this.Ctx.Input.RequestBody)

}

Router.go

Package router

Import (

"github.com/astaxie/beego"

"sayHello/controller"

)

Var hello = controller.SayHelloController {}

Func init () {

Beego.Router ("/", & hello, "POST:SayHello")

}

Main.go

Package main

Import (

"github.com/astaxie/beego"

_ "sayHello/router"

"fmt"

)

Func main () {

Fmt.Println (beego.BConfig.CopyRequestBody)

Beego.Run ()

} after reading the above, do you have any further understanding of how to call the interface in batch in the shell script? If you want to know more knowledge or related content, please follow the industry information channel, thank you for your support.

Tags: Scripts interfaces content directories structures results more knowledge articles industry language information information channels channels access support related Apple Docker Huawei Linux macOS MariaDB Microsoft MySQL NVidia OPPO Reno NVidia Redmi vpn Apple OPPO Reno