gpt4 book ai didi

android - 多个字符集 : text/json; Charset=UTF-8;charset=utf-8 OkHttp Header

转载 作者:行者123 更新时间:2023-11-30 02:11:57 24 4
gpt4 key购买 nike

获取多个字符集:text/json; Charset=UTF-8;charset=utf-8 OkHttp Header 调用 okHttp Library 服务器时。有人知道我该如何解决这个问题。

public String post(String url, RequestBody body) {

Request request = new Request.Builder()
.url(url)
.addHeader("Content-Type","text/json;Charset=UTF-8")
.post(body)
.build();

String str_response="";

Response response;

try {

response = client.newCall(request).execute();

try {

str_response = response.body().string();
System.out.println("POST_BODY_RESPONSE: "+" url "+url+" strresp "+str_response);

} catch (Exception ex){

ex.printStackTrace();
Log.e("POST_BODY_RESPONSE: ",url+" resp "+str_response);
}

} catch (SocketTimeoutException e) {
// TODO Auto-generated catch block
e.printStackTrace();
str_response = "";

}catch (ConnectTimeoutException e) {
// TODO Auto-generated catch block
e.printStackTrace();
str_response = "";

} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();

str_response = "";
}

return str_response;
}

04-30 15:27:12.118: W/System.err(7502): java.lang.IllegalArgumentException: 多个字符集:文本/json;字符集=UTF-8;字符集=utf-8 04-30 15:27:12.118: W/System.err(7502): 在 com.squareup.okhttp.MediaType.parse(MediaType.java:64)

    04-30 15:27:12.118: W/System.err(7502):     at com.squareup.okhttp.Call$RealResponseBody.contentType(Call.java:252)
04-30 15:27:12.118: W/System.err(7502): at com.squareup.okhttp.ResponseBody.charset(ResponseBody.java:86)
04-30 15:27:12.118: W/System.err(7502): at com.squareup.okhttp.ResponseBody.string(ResponseBody.java:82)
04-30 15:27:12.128: W/System.err(7502): at app.app.utils.OkHttp.post(OkHttp.java:75)
04-30 15:27:12.128: W/System.err(7502): at app.app.fragment.Login$2.run(Login.java:226)
04-30 15:27:12.128: W/System.err(7502): at java.lang.Thread.run(Thread.java:856)

最佳答案

你应该修复你的服务器只发送一次字符集。

关于android - 多个字符集 : text/json; Charset=UTF-8;charset=utf-8 OkHttp Header,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29966874/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com