# 实现 HTTP 基本认证 (/zh-CN/realtime-media/speech-to-text/build/start-transcribing-and-translating/http-basic-auth) > For AI agents: see the complete documentation index at [llms.txt](/llms.txt). ## 前提条件 [#前提条件] 本文介绍如何进行 HTTP 基本认证。 已经从声网控制台获取客户 ID 和客户密钥,详见[开通服务](/zh-CN/realtime-media/speech-to-text/build/start-transcribing-and-translating/enable-service)。 ## 生成方法 [#生成方法] 进行 HTTP 基本认证时,你需要使用声网提供的客户 ID 和客户密钥生成一个 Base64 算法编码的凭证,并填入 HTTP 请求头部的 `Authorization` 字段中。本节介绍如何获取用于 HTTP 基本认证的 `Authorization` 字段。 ### 使用三方工具生成 [#使用三方工具生成] 你可以使用[第三方在线工具](https://www.debugbear.com/basic-auth-header-generator)快速得到 Authorization 值。将客户 ID 和客户密钥分别填入 Username 和 Password 框,得到形如 `Authorization: Basic NDI1OTQ3N2I4MzYy...YwZjA=` 的结果。冒号后的内容即是 `Authorization` 值。 ### 使用示例代码生成 [#使用示例代码生成] 复制如下代码,填入你的客户 ID 和客户密钥,即可生成对应的 `Authorization` 字段: ```java tab="Java" tabGroup="operating-systems" import java.io.IOException; import java.net.URI; import java.util.Base64; public class Base64Encoding { public static void main(String[] args) throws IOException, InterruptedException { // 客户 ID // 需要设置环境变量 AGORA_CUSTOMER_KEY final String customerKey = System.getenv("AGORA_CUSTOMER_KEY"); // 客户密钥 // 需要设置环境变量 AGORA_CUSTOMER_SECRET final String customerSecret = System.getenv("AGORA_CUSTOMER_SECRET"); // 拼接客户 ID 和客户密钥并使用 base64 编码 String plainCredentials = customerKey + ":" + customerSecret; String base64Credentials = new String(Base64.getEncoder().encode(plainCredentials.getBytes())); // 创建 authorization header String authorizationHeader = "Basic " + base64Credentials; } } ``` ```go tab="Go" tabGroup="operating-systems" package main import ( "fmt" "strings" "net/http" "io/ioutil" "encoding/base64" ) func main() { // 客户 ID // 需要设置环境变量 AGORA_CUSTOMER_KEY customerKey := os.Getenv("AGORA_CUSTOMER_KEY") // 客户密钥 // 需要设置环境变量 AGORA_CUSTOMER_SECRET customerSecret := os.Getenv("AGORA_CUSTOMER_SECRET") // 拼接客户 ID 和客户密钥并使用 base64 进行编码 plainCredentials := customerKey + ":" + customerSecret base64Credentials := base64.StdEncoding.EncodeToString([]byte(plainCredentials)) // 创建 Authorization header authHeader := "Basic " + base64Credentials // 打印生成的认证头部 fmt.Println(authHeader) } ``` ```php tab="PHP" tabGroup="operating-systems"