Woocommerce 使用 api 使用希伯来语文本创建订单返回错误

Woocommerce create order with hebrew text using the api retuns an error

我正在使用 woocommerce 版本 2.3.10(我无法升级到新版本) 我正在使用 API V2 我正在使用 API 成功创建订单 整个订单文本为英文 一旦其中一个字段中出现希伯来语(例如帐单地址名字),我在尝试创建订单时遇到错误。

我得到的错误是:woocommerce_api_missing_callback_param 任何想法如何解决它? 我尝试将文本编码为 un​​icode 字符串,但在创建订单时该字符串未被解码回希伯来语。 在正规网站用希伯来文开单是没有问题的(不使用api

更新:
我安装了最新版本的 woocommerce,问题依旧

我已经使用 API v2 成功创建了一个订单,在 first_name 字段中使用了希伯来语单词并且它有效。我将代码粘贴在这里,以便您可以对照它检查您的代码。

  $p = $client->orders->create( 
        array (
            'payment_details' => array( 
                "method_id" => "bacs",
                "method_title" => "Direct Bank Transfer",
                "paid" => true
            ),

            'billing_address' => array( 
                "first_name" => "אֱלֹהִ֑ים",
                "last_name" => "Almighty",
                "address_1" => "969 Market",
                "address_2" => "",
                "city" => "San Francisco",
                "state" => "CA",
                "postcode" => "94103",
                "country" => "US",
                "email" => "john.doe@example.com",
                "phone" => "(555) 555-5555" 
            ),

            'shipping_address' => array( 
                "first_name" => "אֱלֹהִ֑ים",
                "last_name" => "Almighty",
                "address_1" => "969 Market",
                "address_2" => "",
                "city" => "San Francisco",
                "state" => "CA",
                "postcode" => "94103",
                "country" => "US"
            ),

            'line_items' => array(
                array( 
                    'product_id' => 579,
                    'quantity' => 2                     
                )               
            ),

            'shippling_lines' => array(
                array(
                    'method_id' => 'flat_rate',
                    'method_title' => 'Flat Rate',
                    'total' => 10                   
                )               
            ),


   ));

在后端订单显示正常

EDIT :根据 OP

的要求添加请求 headers 和 body
Array
(
    [SERVER_SOFTWARE] => Apache/2.4.16 (FreeBSD) PHP/5.6.13 Phusion_Passenger/4.0.59
    [REQUEST_URI] => /wc-api/v2/orders?oauth_consumer_key=ck_640ffa61657f3db1653c10cbc137d4f1ab136a46&oauth_timestamp=1442922853&oauth_nonce=c60ad782ba9f0ee5c2e3e4af980ee21d01980153&oauth_s
ignature_method=HMAC-SHA256&oauth_signature=zv0spywKNaXEbwyEASC3o%2FDexf71jf7CJbF9tEI%2FbCU%3D
    [HOME] => /nonexistent
    [USER] => www
    [FCGI_ROLE] => RESPONDER
    [REDIRECT_STATUS] => 200
    [proxy-nokeepalive] => 1
    [HTTP_HOST] => wordpress
    [HTTP_ACCEPT] => application/json
    [CONTENT_TYPE] => application/json
    [HTTP_USER_AGENT] => WooCommerce API Client-PHP/2.0.1
    [CONTENT_LENGTH] => 734
    [PATH] => /sbin:/bin:/usr/sbin:/usr/bin
    [LD_LIBRARY_PATH] => /usr/local/lib
    [SERVER_SIGNATURE] =>
    [SERVER_NAME] => wordpress
    [SERVER_ADDR] => 192.168.1.11
    [SERVER_PORT] => 80
    [REMOTE_ADDR] => 192.168.1.11
    [DOCUMENT_ROOT] => /usr/home/anand/wordpress/
    [REQUEST_SCHEME] => http
    [CONTEXT_PREFIX] =>
    [CONTEXT_DOCUMENT_ROOT] => /usr/home/anand/wordpress/
    [SERVER_ADMIN] => you@example.com
    [SCRIPT_FILENAME] => /usr/home/anand/wordpress/index.php
    [REMOTE_PORT] => 13999
    [REDIRECT_QUERY_STRING] => oauth_consumer_key=ck_640ffa61657f3db1653c10cbc137d4f1ab136a46&oauth_timestamp=1442922853&oauth_nonce=c60ad782ba9f0ee5c2e3e4af980ee21d01980153&oauth_signature
_method=HMAC-SHA256&oauth_signature=zv0spywKNaXEbwyEASC3o%2FDexf71jf7CJbF9tEI%2FbCU%3D
    [REDIRECT_URL] => /wc-api/v2/orders
    [GATEWAY_INTERFACE] => CGI/1.1
    [SERVER_PROTOCOL] => HTTP/1.1
    [REQUEST_METHOD] => POST
    [QUERY_STRING] => oauth_consumer_key=ck_640ffa61657f3db1653c10cbc137d4f1ab136a46&oauth_timestamp=1442922853&oauth_nonce=c60ad782ba9f0ee5c2e3e4af980ee21d01980153&oauth_signature_method=H
MAC-SHA256&oauth_signature=zv0spywKNaXEbwyEASC3o%2FDexf71jf7CJbF9tEI%2FbCU%3D
    [SCRIPT_NAME] => /index.php
    [PHP_SELF] => /index.php
    [REQUEST_TIME_FLOAT] => 1442922853.0845
    [REQUEST_TIME] => 1442922853
)


{"order":{"payment_details":{"method_id":"bacs","method_title":"Direct Bank Transfer","paid":true},"billing_address":{"first_name":"\u05d0\u05b1\u05dc\u05b9\u05d4\u05b4\u0591\u05d9\u05dd","
last_name":"Almighty","address_1":"969 Market","address_2":"","city":"San Francisco","state":"CA","postcode":"94103","country":"US","email":"john.doe@example.com","phone":"(555) 555-5555"},
"shipping_address":{"first_name":"\u05d0\u05b1\u05dc\u05b9\u05d4\u05b4\u0591\u05d9\u05dd","last_name":"Almighty","address_1":"969 Market","address_2":"","city":"San Francisco","state":"CA",
"postcode":"94103","country":"US"},"line_items":[{"product_id":579,"quantity":2}],"shippling_lines":[{"method_id":"flat_rate","method_title":"Flat Rate","total":10}]}}

编辑 2:添加特定于 C# 的代码

    wc.Headers[HttpRequestHeader.ContentType] = "application/json";
    wc.Encoding = Encoding.UTF8;

    // Send the string as is
    string coupon = "{ \"coupon\": { \"code\": \"new-coupon\", \"type\": \"percent\", \"amount\": \"10\", \"individual_use\": true, \"product_ids\": [], \"exclude_product_ids\": [], \"usage_limit\": \"\", \"usage_limit_per_user\": \"\", \"limit_usage_to_x_items\": \"\", \"expiry_date\": \"\", \"enable_free_shipping\": false, \"product_category_ids\": [], \"exclude_product_category_ids\": [], \"exclude_sale_items\": true, \"minimum_amount\": \"100.00\", \"maximum_amount\": \"0.00\", \"customer_emails\": [], \"description\": \"אֱלֹהִ֑ים\" } }";
    var result = wc.UploadString(url, coupon);

    // Encode the string 
    string coupon = "{ \"coupon\": { \"code\": \"new-coupon1\", \"type\": \"percent\", \"amount\": \"10\", \"individual_use\": true, \"product_ids\": [], \"exclude_product_ids\": [], \"usage_limit\": \"\", \"usage_limit_per_user\": \"\", \"limit_usage_to_x_items\": \"\", \"expiry_date\": \"\", \"enable_free_shipping\": false, \"product_category_ids\": [], \"exclude_product_category_ids\": [], \"exclude_sale_items\": true, \"minimum_amount\": \"100.00\", \"maximum_amount\": \"0.00\", \"customer_emails\": [], \"description\": \"\u05d0\u05b1\u05dc\u05b9\u05d4\u05b4\u0591\u05d9\u05dd\" } }";
    var result = wc.UploadString(url, coupon);
    return result;

解法:
通过给WebClient添加编码解决了问题。
它在没有编码的情况下以英语工作,但是一旦我使用希伯来语文本,我就从 woocommerce API.

中得到错误
WebClient wc = new WebClient();
wc.Headers[HttpRequestHeader.ContentType] = "application/json";
wc.Encoding = Encoding.UTF8;