我正在使用okHTTP对nodejs / express服务器进行https调用。服务器返回一个json字符串
{"result" : true}
这个json字符串在浏览器中显示为{" result":true},但是当我尝试使用OkHTTp读取响应时,我收到以下响应:
<h1>Not Found</h1>
<h2></h2>
<pre></pre>
没有找到json响应。这是我正在使用的Okhttp代码。
public static void sendCredentialsWithPost(LinkedHashMap<String, String> data, String serverUrl, Callback callback) {
Object[] keys = data.keySet().toArray();
FormBody.Builder formBodyBuilder = new FormBody.Builder();
for(Object k : keys) {
String key = (String) k;
formBodyBuilder.add(key, data.get(key).toString());
}
RequestBody formBody = formBodyBuilder.build();
OkHttpClient client = new OkHttpClient();
Request request = new Request.Builder()
.url(serverUrl)
.post(formBody)
.build();
Log.e("wingoku", "url is: "+ serverUrl);
client.newCall(request).enqueue(callback);
}
这是解析okhttp响应的代码:
@Override
public void onResponse(Call call, Response response) throws IOException {
try {
String serverResponse = response.body().string();
}
我做错了什么?我该如何解决?