【发布时间】:2016-09-13 16:54:56
【问题描述】:
我正在尝试在 http POST 请求中发送视频 url,但它对我不起作用,我想我(几乎?)有必要的代码让它工作,否则我错过了一些非常简单的东西?
public void postVideoURL() throws IOException {
String encodedUrl = URLEncoder.encode("http://video.ted.com/talks/podcast/DavidBrooks_2011.mp4", "UTF-8");
URL obj = new URL("http://10.50.0.105:8060/launch/dev?url="+encodedUrl);
HttpURLConnection con = (HttpURLConnection) obj.openConnection();
//add request header
con.setRequestMethod("POST");
// Send post request
con.setDoOutput(true);
OutputStreamWriter wr = new OutputStreamWriter(con.getOutputStream());
System.out.println(con.getResponseCode());
System.out.println(con.getResponseMessage());
wr.flush();
wr.close();
wr.write("");
}
有什么提示可以引导我走向正确的方向吗?
这是我正在尝试做的,但在 C# 中
using System.Net;
using System.Web;
class Program
{
static void Main()
{
string rokuIp = "192.168.0.6";
string channelId = "dev";
string videoUrl = "http://video.ted.com/talks/podcast/DavidBrooks_2011.mp4";
// Note that the query string parameters should be url-encoded
string requestUrl = $"http://{rokuIp}:8060/launch/{channelId}?url={HttpUtility.UrlEncode(videoUrl)}";
using (var wc = new WebClient())
{
// POST the query string with no data
wc.UploadString(requestUrl, "");
}
}
}
以下在终端中使用的 Post 命令有效,这本质上是我想要做的,但是在 Java 中: curl -d "" "http://10.50.0.46:8060/launch/12?url=http%3A%2F%2Fvideo.ted.com%2Ftalks%2Fpodcast%2FDavidBrooks_2011.mp4"
【问题讨论】:
-
定义不工作
-
应用程序启动但视频没有发送到应用程序,代码中没有显示错误,我正在将视频发送到电视上的应用程序。 (我使用 connecteddk 作为 android 应用)
-
您在获取请求中写入视频网址作为参数。如果服务器想要这样,那没关系。
-
@greenapps 视频 url 可以通过终端使用 http post 发送 - [curl -d "" "10.50.0.46:8060/launch/… 所以我假设我可以通过 java 做到这一点?
-
这边?对不起,但我没有看到 curl 帖子。而且您没有解释为什么将该视频网址作为 GET 参数放在网址中,并且还想再次发布。
标签: java android http post ott