【问题标题】:controlling vlc from c# using http requests with credentials使用带有凭据的 http 请求从 c# 控制 vlc
【发布时间】:2018-11-07 09:22:23
【问题描述】:

我想在我的表单中添加一个按钮,将“播放”命令发送到同一网络中的 vlc 播放器。 我正在使用此代码发送 http 请求:

private void VlcPlay_Click(object sender, EventArgs e)
{
    String URI = "http://192.168.1.5:8080/requests/status.xml?command=pl_play";
    WebClient webClient = new WebClient();
    Stream stream = webClient.OpenRead(URI);
    stream.Close();
}

问题在于 vlc 请求:username=blank + password="1234"(可以更改)。 - vlc 不允许设置用户名,它必须为空。 (愚蠢的) - vlc 不允许在没有“某些”密码的情况下进行连接。

我试过这样做:

private void VlcPlay_Click(object sender, EventArgs e)
{
    String URI = "http://192.168.1.5:8080/requests/status.xml?command=pl_play";

    WebClient webClient = new WebClient();
    string credentials = Convert.ToBase64String(
    Encoding.ASCII.GetBytes("" + ":" + "1234"));
    webClient.Headers[HttpRequestHeader.Authorization] = string.Format("Basic {0}", credentials);
    Stream stream = webClient.OpenRead(URI);
    stream.Close();
}

没用。

我如何只发送没有用户名的密码? 谢谢

【问题讨论】:

    标签: c# vlc


    【解决方案1】:

    好吧,在尝试了 100 件事情之后,我自己找到了解决方案 :)

    Encoding.ASCII.GetBytes(null + ":" + "1234"));
    

    【讨论】:

    • 或(更短的形式):Encoding.ASCII.GetBytes(":1234")... 或 Encoding.ASCII.GetBytes("" + ":" + "1234"),这与您的原始示例完全相同。你确定这是修复吗?
    猜你喜欢
    • 1970-01-01
    • 2019-02-19
    • 1970-01-01
    • 2015-05-19
    • 2018-06-23
    • 1970-01-01
    • 2014-11-19
    • 2019-01-01
    • 1970-01-01
    相关资源
    最近更新 更多