向URL发送请求

时间:2015-03-25 23:58:02

标签: c#

我试图在我的办公桌上向我的手机发送请求。我只需输入以下内容即可在浏览器中执行此操作:

http://ip.address/cgi-bin/api-make_call?phonenumber="number"&account="account"&password="password"

这样可以正常工作并拨打"号码"

我已尝试使用:

WebRequest request = HttpWebRequest.Create("http://ip.address/cgi-bin/api-make_call?phonenumber=phonenumber");
request.Credentials = new NetworkCredential(account, password);

我已经使用过HTTPWebResponse并得到类似的内容:

{"response":"error", "body": ""}

但我不确定该怎么做。

3 个答案:

答案 0 :(得分:1)

你必须删除

  request.Credentials = new NetworkCredential(account, password);

上面的代码用于其他用途。

您必须像这样更改第一行

string number = "666666666";
string account = "youraccount";
string password = "password"; 
WebRequest request = HttpWebRequest.Create("http://ip.address/cgi-bin/api-make_call?phonenumber=" + number + "&account=" +account+"&password="+ password);

答案 1 :(得分:0)

您需要字符串中的其他查询字符串参数。他们也可能需要引用,但我不确定。

这是一个函数,如果你传入适当的值,它将为你得到它:

public static string GetCallUrl(string phone, string account, string password)
{
    var baseUrl = "http://ip.address/cgi-bin/api-make_call";

    var queryString = string.Format(
        "?phonenumber=\"{0}\"&account=\"{1}\"&password=\"{2}\"",
        phone, account, password);

    return string.Concat(baseUrl, queryString);
}

用法:

var phone = "2065551212";
var account = "12345";
var password = "letmein";

WebRequest request = HttpWebRequest.Create(GetCallUrl(phone, account, password));

答案 2 :(得分:0)

首先,在导航器中尝试使用正确的网址

http://SERVER_IP/cgi-bin/api-make_call?phonenumber=100&account=0&user=admin&password=admin

你的代码应该是:

WebRequest request = HttpWebRequest.Create("http://SERVER_IP/cgi-bin/api-make_call?phonenumber=100&account=0&user=admin&password=admin")

帐户用于行密钥,不用于记录。

我希望,它适合你。

此致

相关问题