Undergraduate here. Recently I'm practicing developing some Android Apps when I come across this problem. I need to start an API call, using the given format as belows:API request headers and body example
And I choose to use okhttp3 to make the request, here is my code:
RequestBody formBody = new FormBody.Builder()
.add("reply","\""+my_string+"\"")
.add("type","0")
.build();
Request request = new Request.Builder().url("https://cbs-ext.cn-north-4.myhuaweicloud.com/v1/" + projectid + "/taskbot/voicecall/bots/" + botid + "/sessions/" + sessionid)
.addHeader("X-Auth-Token",Xauth)
.addHeader("Content-Type","application/json")
.post(formBody).build();
well, you see I don't think there is anything wrong with my request format, comparing to the given format, however the connection always give back error code:
{"error_code":"CBS.6852","error_msg":"unsupported mediaType, content-type must be application/json"}
I've checked all the other lines and error informations and have confirmed that the problem is caues by my POST request.
You can see that API told me my request is not formatted in json. So I'd like to ask why this error occurs? Have I made some mistakes in makeing request? Or could it be said that my request body is not in json format at all? How should I deal with it?
I'm sorry to say that I'm just in the beginner level of Android dev and API calling, so maybe the question is too silly in your guys' eyes XD. But I still hopefully looking forward to see your words, I need a solution, thanks guys XD.