报错
报错Bad Request只是显式的错误,在ApiException里面有个resp返回的内容,在里面可以看到实际的错误,报错如下
couldn’t get version/kind; json parse error: json: cannot unmarshal string into Go value of type struct
原因
我在replaceClusterCustomObject最后一个参数里填了字符串(通过gson.toJson(obj)来返回),实际上不能传递字符串,直接传obj就好了,或者传bytes,就是不要传字符串。。
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
|
public RequestBody serialize(Object obj, String contentType) throws ApiException {
if (obj instanceof byte[]) {
return RequestBody.create(MediaType.parse(contentType), (byte[])((byte[])obj));
} else if (obj instanceof File) {
return RequestBody.create(MediaType.parse(contentType), (File)obj);
} else if (this.isJsonMime(contentType)) {
String content;
if (obj != null) {
content = this.json.serialize(obj);
} else {
content = null;
}
return RequestBody.create(MediaType.parse(contentType), content);
} else {
throw new ApiException("Content type \"" + contentType + "\" is not supported");
}
}
|