Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/332.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# EasyPost API-打印自定义选项赢得';不要在标签上打印_C#_Easypost - Fatal编程技术网

C# EasyPost API-打印自定义选项赢得';不要在标签上打印

C# EasyPost API-打印自定义选项赢得';不要在标签上打印,c#,easypost,C#,Easypost,这让我一个多小时都在发疯。我是EasyPost的新手,我正在尝试在标签上添加一些自定义文本(在我的特殊情况下,它是要将哪个SKU放入包中),但它似乎从来都不起作用。我使用的是easypost的官方nuget软件包,但我猜它与平台无关 Shipment shipment = new Shipment() { to_address = toAddress, from_address = fromAddress, parcel = parcel }; shipment.Cre

这让我一个多小时都在发疯。我是EasyPost的新手,我正在尝试在标签上添加一些自定义文本(在我的特殊情况下,它是要将哪个SKU放入包中),但它似乎从来都不起作用。我使用的是easypost的官方nuget软件包,但我猜它与平台无关

Shipment shipment = new Shipment() {
    to_address = toAddress,
    from_address = fromAddress,
    parcel = parcel
};

shipment.Create();
var lowestRate = shipment.LowestRate(includeServices: new List<string>() { "First" }, includeCarriers: new List<string>() { "USPS" });

shipment.Buy(lowestRate);

shipment.options.Add("print_custom_1", "this is some sample text");
shipment.options.Add("print_custom_2", "abc");
shipment.options.Add("print_custom_3", "xyz");

shipment.GenerateLabel("pdf");
shipping装运=新装运(){
to_address=toAddress,
from_address=fromAddress,
包裹
};
shipping.Create();
var lowestRate=shipping.lowestRate(includeDevices:new List(){“First”},includeCarriers:new List(){“USPS”});
装运。购买(lowestRate);
shipping.options.Add(“print_custom_1”,“这是一些示例文本”);
装运。选项。添加(“打印自定义2”、“abc”);
装运。选项。添加(“打印自定义3”、“xyz”);
装运。生成标签(“pdf”);

好吧,那太烦人了。当你退后一步时,这是有道理的。问题是在创建装运之前需要设置选项。在我看来,这是一个只关注打印的问题(事实确实如此),但还有其他选项可以并且确实会影响运输成本,这意味着在创建运输时需要设置该选项。即使在创建后但在“购买”之前设置选项也不起作用

见下面的工作代码:

Shipment shipment = new Shipment() {
    to_address = toAddress,
    from_address = fromAddress,
    parcel = parcel
};

//DO THIS BEFORE CREATING!
shipment.options = new Dictionary<string, object>();
shipment.options.Add("print_custom_1", "this is some sample text");
shipment.options.Add("print_custom_2", "abc");
shipment.options.Add("print_custom_3", "xyz");

shipment.Create();
var lowestRate = shipment.LowestRate(includeServices: new List<string>() { "First" }, includeCarriers: new List<string>() { "USPS" });

shipment.Buy(lowestRate);

shipment.GenerateLabel("pdf");
shipping装运=新装运(){
to_address=toAddress,
from_address=fromAddress,
包裹
};
//在创建之前执行此操作!
shipping.options=新字典();
shipping.options.Add(“print_custom_1”,“这是一些示例文本”);
装运。选项。添加(“打印自定义2”、“abc”);
装运。选项。添加(“打印自定义3”、“xyz”);
shipping.Create();
var lowestRate=shipping.lowestRate(includeDevices:new List(){“First”},includeCarriers:new List(){“USPS”});
装运。购买(lowestRate);
装运。生成标签(“pdf”);