You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

使用Aws4RequestSigner签名PAAPI 5请求时遇IncompleteSignature异常

亚马逊PAAPI签名请求报错:IncompleteSignatureException

我正在VS2015窗体应用中,使用Aws4RequestSigner对亚马逊PAAPI的搜索请求进行签名,使用的NuGet包为Aws4RequestSigner。调用API后收到如下错误响应:

{"__type":"com.amazon.paapi5#IncompleteSignatureException","Errors":[{"Code":"IncompleteSignature","Message":"The request signature did not include all of the required components. If you are using an AWS SDK, requests are signed for you automatically; otherwise, go to https://webservices.amazon.com/paapi5/documentation/sending-request.html#signing."}]}

相关代码如下:

private async void Form1_Load(object sender, EventArgs e)
{
    _accessKey = "x";
    _secretKey = "x";
    _service = "ProductAdvertisingAPIv1";
    _region = "us-east-1";
    _requestUri = new Uri("https://webservices.amazon.com/paapi5/searchitems");
    var payload = new
    {
        Keywords = "Harry",
        Marketplace = "www.amazon.com",
        PartnerTag = "x0d-20",
        PartnerType = "Associates",
        Resources = new string[] { "Images.Primary.Small", "ItemInfo.Title", "Offers.Listings.Price" },
        SearchIndex = "All"
    };
    string jsonString = JsonConvert.SerializeObject(payload);
    var content = new StringContent(jsonString, Encoding.UTF8, "application/json");
    var xAmzDate = GetTimeStamp();
    content.Headers.Add("content-encoding", "amz-1.0");
    content.Headers.Add("x-amz-date", xAmzDate);
    content.Headers.Add("x-amz-target", "com.amazon.paapi5.v1.ProductAdvertisingAPIv1.SearchItems");
    var request = new HttpRequestMessage
    {
        Method = HttpMethod.Post,
        RequestUri = _requestUri,
        Content = content
    };
    request.Headers.Host = "webservices.amazon.com";
    var contentType = new MediaTypeHeaderValue("application/json");
    contentType.CharSet = "utf-8";
    request.Content.Headers.ContentType = contentType;
    var signer = new AWS4RequestSigner(_accessKey, _secretKey);
    request = await signer.Sign(request, _service, _region);
    try
    {
        var client = new HttpClient();
        var response = await client.SendAsync(request);

        if (!response.IsSuccessStatusCode)
        {
            var error = await response.Content.ReadAsStringAsync();
        }
        // response.EnsureSuccessStatusCode();
        txtDisplay.Text = await response.Content.ReadAsStringAsync();
    }
    catch (HttpRequestException ex)
    {
        string error = ex.Message;
        txtDisplay.Text = error;
    }
}

private string GetTimeStamp()
{
    return DateTime.UtcNow.ToString("yyyyMMdd\\THHmmss\\Z");
}

我推测问题可能是请求头添加错误,或是Aws4RequestSigner版本过时。

内容的提问来源于stack exchange,提问作者QuietWorld

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.08.04 11:50:25