我正在使用eBay大型商户服务。我已成功使用.NET HttpClient(最终)获得基本的AddFixedPriceItem作业。但是,根据我的AddFixedPriceItem XML文件的内容,对uploadFile作业的响应将返回:
请指定有效格式的文件
我无法确定造成此错误的原因。
示例#1:
我有一个包含2个AddFixedPriceItemRequest
个请求的文件,这个请求会成功上升,而一个包含3个AddFixedPriceItemRequest
个请求的文件则不会。当我从第3个请求中删除一些NameValueList
标记时,它会起作用。对于我删除的NameValueList
标记,我看不出任何错误或不同之处。如果我自己发送第三个请求,而不删除任何标签,它就能完美运行。
示例#2:
我在一个文件中有1 AddFixedPriceItemRequest
个请求,其中包含Description
标记的CDATA信息(对于HTML值),这些信息会成功上升,而另一个文件包含2个AddFixedPriceItemRequest
个请求也包含几乎相同的CDATA值但不起作用。如果我从添加的第二个请求中删除CDATA,它仍然无效。如果我也从第一次请求中删除CDATA(第一次成功地自动上升),那么它确实有效。
我真的很困惑。关于哪个文件被认为是有效的"有效"似乎没有押韵和理由。
以下是失败请求的示例:(SO似乎没有采用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=""; start-info="text/xml" Host: storage.sandbox.ebay.com Content-Length: 3041 Expect: 100-continue --MIME_boundary Content-Type: application/xop+xml Content-ID: Content-Transfer-Encoding: binary 1710zip5000867513450008489744 --MIME_boundary Content-Type: application/octet-stream Content-Transfer-Encoding: base64 Content-ID: UEsDBBQAAAAIAMZZ9UhnranV5gUAADYmAAAPACQAYWRkbGlzdGluZ3MueG1sCgAgAAAAAAABABgA4roeimLj0QE1N5fd4t3RAex2PDlG3dEB7Vptc9o4EP4rmny59kOxDZiXjOoZXppL5kjDxaG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以下是我如何使用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
答案 0 :(得分:0)
我终于得到了答案。 “100继续”消息给了我所需的线索。我花了太多时间试图了解间歇性操作。
1)你的代码永远不会真正起作用。当您运行LMS项目时,将建立一个cookie,为您的请求设置默认设置。因此,运行LMS后,您的代码将始终有效。如果您从IE历史记录中删除cookie,您的代码将无法运行。
2)“100继续消息”用于“块模式”(非流)。如果看到1.1将默认为块模式,那么Net库默认为HTTP 1.1和大多数服务器。服务器发送一个块,但是Net库中没有办法从服务器请求第二个块。因此连接超时并失败。解决此问题的唯一方法是将HTTP请求设置为HTTP 1.0,该请求不支持块模式,服务器将响应作为流发送回来。
试试这个
HttpWebRequest request = (HttpWebRequest)WebRequest.Create("URL");
request.ProtocolVersion = HttpVersion.Version10;
另请参阅:Set HTTP protocol version in HttpClient
查看失败的第一行请求1.1