-1
{"method": "setActiveApp", "params": [{"uri":"localapp://webappruntime?        url=http://xxx.xxx.xxx.xxx:8125/active","data":""}], "id": 1}

当尝试在 HTTP 帖子中发送上述 json 数据时,我总是从服务器收到 ILLEGAL JSON 响应。实际上,wireshark 日志显示,而不是上述数据,正在发送以下 json 正文(“params”之后出现的额外“:”)。我该如何解决这个问题?

{"method": "setActiveApp", "params": "[{"uri":"localapp://webappruntime?        url=http://xxx.xxx.xxx.xxx:8125/active","data":""}]", "id": "1"}
4

1 回答 1

1

使用此代码。根据口味添加一些尝试/捕捉。

import org.apache.http.HttpEntity;
import org.apache.http.HttpResponse;
import org.apache.http.client.HttpClient;
import org.apache.http.client.methods.HttpPost;
import org.apache.http.entity.StringEntity;
import org.apache.http.impl.client.DefaultHttpClient;

final String CODEPAGE = "UTF-8";
HttpPost post = new HttpPost(yourUrl);
post.setEntity(new StringEntity(yourJson.toString(), CODEPAGE));
HttpResponse resp = null;
HttpClient httpclient = new DefaultHttpClient();
resp = httpclient.execute(post);
于 2013-11-06T04:09:42.027 回答