我的Java代码如下所示,一切对我来说都很好。我面临的问题是,当我通过将JSONObject转换为String将该值传递给服务器时,由于该服务器无法解析URL,因此对该URL进行了编码。有没有没有编码就可以传递hls_playback_url的方法
[我的hls_playback_url的编码如下:“ hls_playback_url”:“ https://test-i.akamaihd.net/hls/live/1004008/64b4de64/playlist.m3u8”
但是我希望将类似“ hls_playback_url”:“ https://test-i.akamaihd.net/hls/live/1004008/64b4de64/playlist.m3u8”的URL转到服务器
JSONObject jsonParam = new JSONObject();
jsonParam.put("connectionCode", result.getConnectionCode());
jsonParam.put("enabled", true);
jsonParam.put("hls_playback_url", result.getHlsPlaybackUrl());
jsonParam.put("entryName", result.getName());
jsonParam.put("profile", "wowza-cdn");
jsonParam.put("sourceStreamName", result.getName());
jsonParam.put("wowzaCloud.adaptiveStreaming",false);
jsonParam.put("wowzaCloud.accountApiKey", "FZQ***");
jsonParam.put("wowzaCloud.accountAccessKey", "Wn0***");
jsonParam.put("wowzaCloud.targetId", result.getId());
String postResponse = doPostRequest("http://localhost:8087/v2/servers/_defaultServer_/vhosts/_defaultVHost_/applications/live/pushpublish/mapentries/"+result.getName(),jsonParam);
private String doPostRequest(String url, JSONObject json) throws IOException {
OkHttpClient client = new OkHttpClient();
MediaType JSON = MediaType.parse("application/json; charset=utf-8");
Log.e("MyJson",json.toString());
RequestBody body = RequestBody.create(JSON, json.toString()); //the hls_playback_url gets encoded, due to that unable to insert this value to the server
Request request = new Request.Builder()
.url(url)
.post(body)
.build();
Response response = client.newCall(request).execute();
return response.body().string();
}