我正在尝试在 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 "