【问题标题】:Error 414 When sending invoice to Amazon MWS with _UPLOAD_VAT_INVOICE_使用 _UPLOAD_VAT_INVOICE_ 向亚马逊 MWS 发送发票时出现错误 414
【发布时间】:2020-05-16 18:05:41
【问题描述】:

我正在尝试按照本指南中的 java 示例通过 _UPLOAD_VAT_INVOICE_ 向亚马逊 mws 发送发票: Link

pdf 文件是 85 kb 的简单发票 错误是状态码 414,即“Uri 太长”

调试亚马逊原始类 MarketplaceWebServiceClient 我看到了这个:

if( request instanceof SubmitFeedRequest ) { // For SubmitFeed, HTTP body is reserved for the Feed Content and the function parameters // are contained within the HTTP header SubmitFeedRequest sfr = (SubmitFeedRequest)request; method = new HttpPost( config.getServiceURL() + "?" + getSubmitFeedUrlParameters( parameters ) );

getSubmitFeedUrlParameters 方法获取每个参数并将其添加到查询字符串。这些参数之一是 contentMD5 来自: 字符串内容MD5 = Base64.encodeBase64String(pdfDocument); 所以有一个非常大的字符串表示作为参数传递的pdf文件。这会导致错误 414

但该类是取自 MaWSJavaClientLibrary-1.1.jar 的原始类

有人可以帮帮我吗?

谢谢

【问题讨论】:

  • 我在调试后添加了一些额外的信息

标签: amazon-web-services amazon-mws


【解决方案1】:

在过去的 2 天里,我一直在解决同样的问题, 我这样改了,现在可以用了

InputStream contentStream = new ByteArrayInputStream(pdfDocument);
String contentMD5 =computeContentMD5Header(new ByteArrayInputStream(pdfDocument));

public static String computeContentMD5Header(InputStream inputStream) {

        // Consume the stream to compute the MD5 as a side effect.
        DigestInputStream s;
        try {
            s = new DigestInputStream(inputStream,
                    MessageDigest.getInstance("MD5"));

            // drain the buffer, as the digest is computed as a side-effect
            byte[] buffer = new byte[8192];
            while (s.read(buffer) > 0)
                ;

            return new String(

            org.apache.commons.codec.binary.Base64.encodeBase64(s
                    .getMessageDigest().digest()), "UTF-8");
        } catch (NoSuchAlgorithmException e) {
            throw new RuntimeException(e);
        } catch (IOException e) {
            throw new RuntimeException(e);
        }
    }

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多