# 常见问题

## 请求或响应问题

### 1，参数值乱码或缺失

**检查是否UTF-8编码**

```
//以HttpClient为例
//a: 一般Get请求默认为此类型
import org.apache.http.client.methods.HttpGet;
httpGet.setHeader("Content-Type","application/x-www-form-urlencoded;charset=UTF-8");

//或者b: post方式设置body格式为json
import org.apache.http.client.methods.HttpPost;
httpPost.setHeader("Content-Type","application/json;charset=UTF-8");

//c: 同时设置可能会报错，本文档也并无Post方式接口同时传递query参数和body参数
```

**是否对请求参数进行encode**

当发送get请求（或类似post请求：url?key=中文和特殊符号），即本文档中所指的[query参数](/api-explorer/fu-lu/shu-ju-qian-ming-guo-cheng.md#shu-ju-ding-yi)，由于参数实际是以拼接在url后方的方式进行参数传递的，如果不对中文或非ascii字符进行urlEncode，则会出现参数值乱码或丢失的情况。此时可对参数值进行urlEncode后，再进行参数设置并发送请求。

```
//以HttpClient为例
// 传入的query参数
Map<String,String> queryParamMap ...;
//开始设置http请求参数
List<NameValuePair> param = new ArrayList<>();
for (Map.Entry<String, String> entry : paramMap.entrySet()) {
    param.add(new BasicNameValuePair(entry.getKey(),entry.getValue()) );
}
httpPost.setEntity(new UrlEncodedFormEntity(param, StandardCharsets.UTF_8));

//当传入的是body参数时
httpPost.setEntity(
    new StringEntity(json, 
        ContentType.create("application/json", StandardCharsets.UTF_8)));

```

**结果解析时，是否设定为UTF-8编码**

收到服务端结果时，Header部分一般为数字或英文字符组成，不会出现乱码。body部分请使用UTF-8编码进行接收。

```
//http response
String result = EntityUtils.toString(response.getEntity(),StandardCharsets.UTF_8);
```

### 2，签名问题

1，打印或手工拼接出签名校验不通过的请求的签名内容字符串，使用工具进行HMAC-SHA256签名，比较和发送请求时的签名是否一致，核对签名算法本身

2，对照[签名步骤](/api-explorer/fu-lu/shu-ju-qian-ming-guo-cheng.md#tong-yong-qian-ming-bu-zhou)，检查签名内容字符串是否拼接无误，是否多了空值或空对象：'' "" {} 之类的，又是否有换行符的差异，如：\n \r\n

2，检查是否存在上方参数值乱码或缺失的问题，导致发送端的签名内容和服务端接收到的报文内容有差异，注意如果是对参数值以及body数据体，不是encode转码后的值进行签名

3，签名key是否正确

## 异常提示


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## Querying This Documentation
If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://asiabill.gitbook.io/api-explorer/fu-lu/chang-jian-wen-ti.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
