gpt4 book ai didi

c# - eBay FileTransferService - 请指定具有有效格式的文件

转载 作者:太空宇宙 更新时间:2023-11-03 15:17:25 26 4
gpt4 key购买 nike

我在 eBay Large Merchant Services 工作。我已经成功地让基本的 AddFixedPriceItem 作业使用 .NET HttpClient(最终)工作。但是,根据我的 AddFixedPriceItem XML 文件的内容,对 uploadFile 作业的响应将返回:

Please specify a File with Valid Format

我无法查明导致此错误的原因。

示例#1:

我有一个包含 2 个 AddFixedPriceItemRequest 请求的文件,它们会成功启动,还有一个文件包含 3 个 AddFixedPriceItemRequest 请求,但不会成功。当我从第三个请求中删除一些 NameValueList 标签时,它会起作用。我没有发现我删除的那些 NameValueList 标签有任何问题或不同之处。如果我自己发送第三个请求,而不删除任何标签,它会完美运行。

示例 #2:

我在一个文件中有 1 个 AddFixedPriceItemRequest 请求,其中包含 Description 标签(对于 HTML 值)的 CDATA 信息,该请求会成功,另一个文件有 2 AddFixedPriceItemRequest 请求也包含几乎相同的 CDATA 值,但不起作用。如果我从添加的第二个请求中删除 CDATA,它仍然不起作用。如果我也从第一个请求中删除了 CDATA(它第一次成功地自行启动)那么它就可以工作。

我真的很困惑。似乎没有关于哪个文件被认为是“有效”的押韵和理由。

下面是失败请求的示例:(Stack Overflow 似乎没有获取 Content-ID - 但它们在那里。)

POST http://storage.sandbox.ebay.com/FileTransferService HTTP/1.1
X-EBAY-SOA-SECURITY-TOKEN: xxx
X-EBAY-SOA-SERVICE-NAME: FileTransferService
X-EBAY-SOA-SERVICE-VERSION: 1.0.0
X-EBAY-SOA-OPERATION-NAME: uploadFile
X-EBAY-SOA-OPERATION-FORMAT: XML
Content-Type: multipart/related; boundary="MIME_boundary"; type="application/xop+xml"; start="<0.urn:uuid:9ce221c2-659d-4852-a166-51dcbccf68d9>"; start-info="text/xml"
Host: storage.sandbox.ebay.com
Content-Length: 3041
Expect: 100-continue

--MIME_boundary
Content-Type: application/xop+xml
Content-ID: <0.urn:uuid:9ce221c2-659d-4852-a166-51dcbccf68d9>
Content-Transfer-Encoding: binary

<?xml version="1.0" encoding="utf-8"?><uploadFileRequest xmlns="http://www.ebay.com/marketplace/services"><fileAttachment><Data><xop:Include href="cid:urn:uuid:c6f7fc4d-352b-414f-8638-6c9bdf40519e" xmlns:xop="http://www.w3.org/2004/08/xop/include"/></Data><Size>1710</Size></fileAttachment><fileFormat>zip</fileFormat><fileReferenceId>50008675134</fileReferenceId><taskReferenceId>50008489744</taskReferenceId></uploadFileRequest>
--MIME_boundary
Content-Type: application/octet-stream
Content-Transfer-Encoding: base64
Content-ID: <urn:uuid:c6f7fc4d-352b-414f-8638-6c9bdf40519e>

UEsDBBQAAAAIAMZZ9UhnranV5gUAADYmAAAPACQAYWRkbGlzdGluZ3MueG1sCgAgAAAAAAABABgA4roeimLj0QE1N5fd4t3RAex2PDlG3dEB7Vptc9o4EP4rmny59kOxDZiXjOoZXppL5kjDxaG5+9QR9gJqbcsny2m4X38rgwEbmJ57zDWd8inSrvaRdq1dPRKh/TT4PGSKvXv2Fiyawz38lUKiEvIcBlHy9iKV0SVM2fKSxTy5hP6ozxIYiDAWEUQquXDoNTAfpEM/gEy4iJxuy6ZG3qEuV3AzdExqrFvUyA16vn/Fn8EfS+7BjYJwPfe/n/qdlEKOcNkpm4MD0ceJS42ikD4yGfFoPoInCJxrPl9QoyA6sm69HocOmIK5kMtbFsdo0QsC8QV8R8kUqHFESQci8rlCFPTWMk10fVeC6jRScunoteZtOkilhMjT0iGK8x4dQuJJHmtbZ8h4JAKMIhmhGwqnJMPRda9lN6/e3PX7xP2Cojc9GRJrNYJcBUJIMmJhTHhE7nhA+jJNFuDjXxH9jT7s4tMhT2KmvMUDD+GWPTsYj7KI3kRPGHz0+kEy7zNOeAtqIXzH/W1CjWNKOhIey+YwO23Tosamn8XZjcHjM+4lDn3PQvjAghRGPFGrrtOXLPKpkbVpptyGAr9YJlipS5ZloNvx+xLMTviqIQkfghNhYQZOycMyhiLeNQvEHKLKUP8dZQBS6c+RfaEi3MDtEYNMRpXwr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dthTo7D/FNct+wbcsa3vLam1uWZ2vXLIOzZTVdxaQK2D6nlOaB8+KKJkJGaJf61uAXw1eLYNSWPHExXMlFhJvRZi0ulzLaoXATed4hcNCTO6FCA/UqLsZlolqWxJZFx6lB7BWikpYu1E7yc7Sq9L7age4CHjL5hEo7lVC/SCCA28LdfOpEsoRBx+rgXBfLXAzDDn2VNm7zvHK8J3fDXJS8WM8HGwp0Et5OcAV1a3zb1znl4Of+OWg2dh/Oai36xVeDr7pmrn3I5fZsVseXortrj1tWp1Wt9Xw/DbzZzbmadOr8COXcex/w5x/AFBLAQItABQAAAAIAMZZ9UhnranV5gUAADYmAAAPACQAAAAAAAAAIAAAAAAAAABhZGRsaXN0aW5ncy54bWwKACAAAAAAAAEAGADiuh6KYuPRATU3l93i3dEB7HY8OUbd0QFQSwUGAAAAAAEAAQBhAAAANwYAAAAA
--MIME_boundary--

以下是我使用 HttpClient 发送请求的方式:

    byte[] data;
long fileLength;
var uuidRequest = Guid.NewGuid().ToString();
var uuidAttachment = Guid.NewGuid().ToString();

using (FileStream fs = File.OpenRead(filePath))
{
data = new byte[fs.Length];
fs.Read(data, 0, data.Length);
fileLength = fs.Length;
}

var xml =
"<?xml version=\"1.0\" encoding=\"utf-8\"?>" +
"<uploadFileRequest xmlns=\"http://www.ebay.com/marketplace/services\">" +
"<fileAttachment>" +
"<Data><xop:Include href=\"cid:urn:uuid:" + uuidAttachment + "\" xmlns:xop=\"http://www.w3.org/2004/08/xop/include\"/></Data>" +
"<Size>" + fileLength + "</Size>" +
"</fileAttachment>" +
"<fileFormat>zip</fileFormat>" +
"<fileReferenceId>" + fileReferenceID + "</fileReferenceId>" +
"<taskReferenceId>" + jobID + "</taskReferenceId>" +
"</uploadFileRequest>";

var multippartcontent = new MultipartContent("related", "MIME_boundary");
multippartcontent.Headers.Remove("Content-Type");
multippartcontent.Headers.TryAddWithoutValidation("Content-Type", string.Format("multipart/related; boundary=\"MIME_boundary\"; type=\"application/xop+xml\";start=\"<0.urn:uuid:{0}>\";start-info=\"text/xml\"", uuidRequest));

var content = new StringContent(xml);
content.Headers.ContentType = new MediaTypeHeaderValue("application/xop+xml");
content.Headers.Add("Content-ID", string.Format("<0.urn:uuid:{0}>", uuidRequest));
content.Headers.TryAddWithoutValidation("Content-Transfer-Encoding", "binary");
multippartcontent.Add(content);

var attachmentContent = new StringContent(Convert.ToBase64String(data));
attachmentContent.Headers.ContentType = new MediaTypeHeaderValue("application/octet-stream");
attachmentContent.Headers.TryAddWithoutValidation("Content-Transfer-Encoding", "base64");
attachmentContent.Headers.Add("Content-ID", string.Format("<urn:uuid:{0}>", uuidAttachment));
multippartcontent.Add(attachmentContent);


var uploadFileResp = httpclient.PostAsync(ftServiceUrl, multippartcontent).Result.Content.ReadAsStringAsync().Result;

我会注意到,当我上传同一个文件时,它不适用于来自 eBay (https://ebaydts.com/eBayKBDetails?KBid=1338) 的 LMS 项目。这让我觉得我在我的代码中做错了什么 - 也许与我的编码方式有关?

HTTP 响应

HTTP/1.1 200 OK
Server: Apache-Coyote/1.1
X-EBAY-SOA-SERVICE-METRICS: 455075973
X-EBAY-SOA-REQUEST-ID: 15613449-f630-a471-d2d4-ec64ffff71c7!FileTransferService!10.71.29.45!v3apibulksandboxcore[]
X-EBAY-SOA-SERVICE-VERSION: 1.1.0
X-EBAY-SOA-MESSAGE-PROTOCOL: NONE
X-EBAY-SOA-RESPONSE-DATA-FORMAT: XML
X-EBAY-SOA-OPERATION-NAME: uploadFile
X-EBAY-SOA-SERVICE-NAME: {http://www.ebay.com/marketplace/services}FileTransferService
Content-Type: text/xml;charset=UTF-8
Transfer-Encoding: chunked
Date: Fri, 22 Jul 2016 15:41:19 GMT

1cd
<?xml version='1.0' encoding='UTF-8'?><uploadFileResponse xmlns="http://www.ebay.com/marketplace/services"><ack>Failure</ack><errorMessage><error><errorId>11</errorId><domain>Marketplace</domain><severity>Error</severity><category>Application</category><message>Please specify a File with Valid Format</message><subdomain>FileTransfer</subdomain></error></errorMessage><version>1.1.0</version><timestamp>2016-07-22T15:41:20.118Z</timestamp></uploadFileResponse>
0

最佳答案

我终于得到了答案。 “100 继续”消息给了我所需的线索。我花了太多时间试图了解间歇性操作。

1) 您的代码从来没有真正起作用。当您运行 LMS 项目时,会建立一个 cookie,它会为您的请求设置默认设置。因此,您的代码在运行 LMS 后将始终有效。如果您从 IE 历史记录中删除 cookie,您的代码将永远无法运行。

2) “100 条继续消息”用于“ block 模式”(不是流)。 Net 库默认为 HTTP 1.1 和大多数服务器,当 see 1.1 将默认为 block 模式时。服务器发送一个 block ,但 Net 库中没有办法从服务器请求第二个 block 。因此连接超时并失败。解决此问题的唯一方法是将 HTTP 请求设置为不支持 block 模式的 HTTP 1.0,服务器将以流的形式发回响应。

试试这个

            HttpWebRequest request = (HttpWebRequest)WebRequest.Create("URL");
request.ProtocolVersion = HttpVersion.Version10;

另请参阅:Set HTTP protocol version in HttpClient

查看失败的第一行请求,其中包含 1.1

关于c# - eBay FileTransferService - 请指定具有有效格式的文件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38491524/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com