我已经阅读了 Stack 上的其他一些帖子,但我无法让它发挥作用。当我在 Windows 机器上的 git 中运行 curl 命令时它工作正常,但是当我将它转换为 asp.net 时它不起作用:
private void BeeBoleRequest()
{
string url = "https://mycompany.beebole-apps.com/api";
WebRequest myReq = WebRequest.Create(url);
string username = "e26f3a722f46996d77dd78c5dbe82f15298a6385";
string password = "x";
string usernamePassword = username + ":" + password;
CredentialCache mycache = new CredentialCache();
mycache.Add(new Uri(url), "Basic", new NetworkCredential(username, password));
myReq.Credentials = mycache;
myReq.Headers.Add("Authorization", "Basic " + Convert.ToBase64String(new ASCIIEncoding().GetBytes(usernamePassword)));
WebResponse wr = myReq.GetResponse();
Stream receiveStream = wr.GetResponseStream();
StreamReader reader = new StreamReader(receiveStream, Encoding.UTF8);
string content = reader.ReadToEnd();
Response.Write(content);
}
这是 BeeBole API。它非常直接。http://beebole.com/api但是当我运行上述代码时出现以下 500 错误:
远程服务器返回错误:(500) 内部服务器错误。