目录

示例代码

cURL

curl --location --request POST 'https://xxxxxx/v1/weather/live/basic' --header 'Authorization: Bearer abcdefghijk' --header 'Content-Type: application/json' --data-raw '{
"cityCode": "106566"
}'

Python-Requests

import requests
import json
url = "https://xxxxxx/v1/weather/live/basic"
payload = json.dumps({
"cityCode": "106566"
})
headers = {
'Authorization': 'Bearer abcdefghijk',// 替换鉴权token
'Content-Type': 'application/json'
}
response = requests.request("POST", url, headers=headers, data=payload)
print(response.text)

Java-OkHttp

OkHttpClient client = new OkHttpClient().newBuilder()
  .build();
MediaType mediaType = MediaType.parse("application/json");
RequestBody body = RequestBody.create(mediaType, "{\"cityCode\": \"106566\"}");
Request request = new Request.Builder()
  .url("https://xxxxxx/v1/weather/live/basic")
  .method("POST", body)
  .addHeader("Authorization", "Bearer abcdefghijk")  // 替换鉴权token
  .addHeader("Content-Type", "application/json")
  .build();  
Response response = client.newCall(request).execute();

Go-Native

package main
import (
"fmt"
"strings"
"net/http"
"io/ioutil"
)
func main() {
  url := "https://xxxxxx/v1/weather/live/basic"
  method := "POST"
  payload := strings.NewReader(`{`+"
"+`
"cityCode": "106566"`+"
"+`
}`)
  client := &http.Client {
  }
  req, err := http.NewRequest(method, url, payload)
  if err != nil {
    fmt.Println(err)
    return
  }
  req.Header.Add("Authorization", "Bearer abcdefghijk")
  req.Header.Add("Content-Type", "application/json")
  res, err := client.Do(req)
  if err != nil {
    fmt.Println(err)
    return
  }
  defer res.Body.Close()
  body, err := ioutil.ReadAll(res.Body)
  if err != nil {
    fmt.Println(err)
    return
  }
  fmt.Println(string(body))
}