Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

How to call API in batch in shell script

2025-01-18 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Internet Technology >

Share

Shulou(Shulou.com)06/02 Report--

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.

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Internet Technology

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report