10

我正在尝试在 C# 代码中实现vuforia api 。

我从服务器收到一个错误。

C#代码:

ASCIIEncoding Encoding = new ASCIIEncoding();
MD5 md5 = MD5.Create();
string requestPath = "/targets";
string serviceURI = "https://vws.vuforia.com"+ requestPath;
string httpVerb = "GET";
var contentMD5bytes = md5.ComputeHash(Encoding.GetBytes(""));
string contentMD5 = BitConverter.ToString(contentMD5bytes).Replace("-", "");
string contentType = "";
System.Threading.Thread.CurrentThread.CurrentCulture = new System.Globalization.CultureInfo("en-US");
string date = string.Format("{0:r}", DateTime.Now.ToUniversalTime());
string StringToSign = String.Format("{0}\n{1}\n{2}\n{3}\n{4}", httpVerb, contentMD5, contentType, date, requestPath); // HTTP-Verb, Content-MD5, Content-Type, Date, Request-Path;
HMACSHA1 sha1 = new HMACSHA1(System.Text.Encoding.ASCII.GetBytes(secretKey));
byte[] sha1Bytes = Encoding.GetBytes(StringToSign);
MemoryStream stream = new MemoryStream(sha1Bytes);
byte[] sha1Hash = sha1.ComputeHash(stream);
string signature = System.Convert.ToBase64String(sha1Hash);

HttpWebRequest request = (HttpWebRequest)HttpWebRequest.Create(serviceURI);
request.Headers.Add("Authorization", string.Format("VWS {0}:{1}", accessKey, signature));
request.Date = DateTime.Now.ToUniversalTime();

try
{
    using (HttpWebResponse responses = request.GetResponse() as HttpWebResponse)
    {
        if (responses.StatusCode == HttpStatusCode.OK)
        {
            // Do stuff with response.GetResponseStream();
        }
    }
}
catch (WebException ex)
{

}

到达时出现以下错误

WebResponse tResponse = tRequest.GetResponse();

错误:{“远程服务器返回错误:(401)未经授权。”}

我提到了以下网址

https://developer.vuforia.com/forum/qcar-api/vms-api-using-c

任何人都可以为此提供解决方案。

4

0 回答 0