(reqUrl string, reqParams map[string]interface{}, headers map[string]string)
| 209 | } |
| 210 | |
| 211 | func (target HttpClient) put(reqUrl string, reqParams map[string]interface{}, headers map[string]string) (string, error) { |
| 212 | jsonBytes, err := json.Marshal(reqParams) |
| 213 | if err != nil { |
| 214 | return "", err |
| 215 | } |
| 216 | httpRequest, err := http.NewRequest("PUT", reqUrl, bytes.NewBuffer(jsonBytes)) |
| 217 | if err != nil { |
| 218 | return "", err |
| 219 | } |
| 220 | |
| 221 | // client |
| 222 | httpClient := getClient(reqUrl, target.TimeOut) |
| 223 | |
| 224 | // 添加请求头 |
| 225 | headers["Content-Type"] = "application/json" // 后续可根据需要增加其他的类型 |
| 226 | for k, v := range headers { |
| 227 | httpRequest.Header.Add(k, v) |
| 228 | } |
| 229 | |
| 230 | // 发送请求 |
| 231 | SmartIDELog.Debug(formatRequest(httpRequest, reqParams)) |
| 232 | httpResponse, err := httpClient.Do(httpRequest) |
| 233 | if err != nil { |
| 234 | return "", err |
| 235 | } |
| 236 | responseBody, err := parsingResponse(httpResponse) |
| 237 | if err != nil { |
| 238 | return "", err |
| 239 | } |
| 240 | defer httpResponse.Body.Close() |
| 241 | if httpResponse.StatusCode != 200 { |
| 242 | return "", errors.New(httpResponse.Status) |
| 243 | } |
| 244 | if len(string(responseBody)) == 0 { |
| 245 | return "", errors.New("reponse body is empty") |
| 246 | } |
| 247 | return string(responseBody), err |
| 248 | |
| 249 | } |
| 250 | |
| 251 | func (target HttpClient) post(reqUrl string, |
| 252 | reqParams map[string]interface{}, contentType string, files []UploadFile, headers map[string]string) ( |
no test coverage detected