AWS 400错误请求错误C#

时间:2016-12-15 02:29:54

标签: c# amazon-web-services httpwebrequest

我的任务是开发一个将数据发布到客户端的Amazon Web Service API的应用程序。来自客户端的说明是我必须使用URL方法http://ec。*******。compute.amazonaws.com/api并给我一个用于身份验证的令牌。

我的C#代码看起来像这样

SystemSettings _Settings = GetSystemSettings(); //URL and Token values
try
{
    JObject jsonObject = GetJsonData();
    WebRequest request = HttpWebRequest.Create(_Settings.HttpService);
    if (!string.IsNullOrEmpty(_Settings.BearerToken))
    {
        request.PreAuthenticate = true;
        request.Headers.Add(HttpRequestHeader.Authorization, "Bearer " + _Settings.BearerToken);
     }
     //Uploading JSON
     request.ContentType = "application/json; charset=utf-8";
     //using Http POST Method
     request.Method = "POST";
     //Start uploading data
     StreamWriter httpStream = new StreamWriter(request.GetRequestStream());
     httpStream.Write(jsonObject.ToString());
     httpStream.Close(); // Close stream
     httpStream.Dispose(); //Dispose stream

     //Check for response from the web server
     WebResponse response = request.GetResponse(); //Error comes here
     .
     .
     .
     .
}
catch(Exception ex)
{
    _log.Error("ERROR Uploading to stream(" + _Settings.HttpService + ")", ex);
}

请求以400 Bad Request结束。这是否需要使用Amazon SDK连接才能使用Bearer Token?

客户说了以下内容:

  

我们的API身份验证是RFC6750,您能否请求   API如下:

POST /api/ HTTP/1.1
Host: ec.************.compute.amazonaws.com
Authorization: Bearer ***TOKEN***

0 个答案:

没有答案