【发布时间】:2017-10-17 10:20:45
【问题描述】:
我已尝试转换以下代码
<?php
// requires PHP cURL http://no.php.net/curl
$datatopost = array (
"supplier_id" => "1",
"token" => "xYRPKcoakMoiRzWgKLV5TqPSdNAaZQT",
"ci_lineitem_ids" => json_encode ( array (54553919, 54553920) ),
);
$ch = curl_init ("https://scm.commerceinterface.com/api/v4/mark_exported");
curl_setopt ($ch, CURLOPT_POST, true);
curl_setopt ($ch, CURLOPT_POSTFIELDS, $datatopost);
curl_setopt ($ch, CURLOPT_RETURNTRANSFER, true);
$response = curl_exec ($ch);
if( $response ) {
$response_json = json_decode( $response );
if( $response_json->success == true ) {
//Successfully marked as exported (only items which are not already marked exported
} else {
}
}
使用 C# 中的 HTTP 客户端,使用如下形式的 url 编码内容类代替 PHP 中的 $datatopost 数组
FormUrlEncodedContent markExportedContent = new FormUrlEncodedContent(new[] {
new KeyValuePair<string,string>("supplier_id",country.supplier_id),
new KeyValuePair<string, string>("token",country.token),
new KeyValuePair<string, string>("ci_lineitem_id", JsonConvert.SerializeObject(country.ci_lineitem_ids))
});
然后使用 http 客户端将其发布到 API 但是我得到以下响应
{"reason": "Missing Parameters (ci_lineitem_ids).", "reason_code": 400, "success": false}
我认为它与 Newtonsoft Json 包中的 JsonConvert.SerializeObject(country.ci_lineitem_ids) 有关,我正在使用它从字符串数组转换为 json 编码数组,如 PHP 代码中所示。
任何人都能够提供一些想法,说明为什么这不能按预期工作,因为我现在对此一无所知,在此之前尝试了多种不同的方法来做到这一点?
【问题讨论】:
-
你忘记了
ci_lineitem_id上的“s”