php curl HTTP POST字符集失败

时间:2018-07-27 13:32:55

标签: php api http curl post

由于无法解决自己的失败,我感到非常绝望。

我已经编写了一个WordPress插件,该插件将在Woocommerce中作为产品创建或更新的书及其所有信息发送到Abebooks-API。 一切正常,这本书是蜜蜂创作的,但是有一个错误:

德语字母中出现的Ää,Öö,Üü和ß等字母显示错误。我为测试目的制作了一本书,标题为“ÖhärnüÄrnöÜß”,该书正像这样在Abebooks上展示:,“âhärnüÄrnöÃÃß”。 对我来说,似乎正在发送UTF-8蜂,并将蜂转换为ISO-8859-1。 Abebooks的API仅接受ISO-8859-1。

有趣的是,我使用以下标头发送了HTTP POST: ,,内容类型:文本/纯文本; charset = ISO-8859-1”。这是我编写的代码的主要部分:

$post_string = '<?xml version="1.0" encoding="ISO-8859-1"?>
            <inventoryUpdateRequest version="1.0">
                <action name="bookupdate">
                    <username>hidden..</username>
                    <password>not here..</password>
                </action>
                <AbebookList>
                    <Abebook>
                        <transactionType>ADD</transactionType>
                        <vendorBookID>' . $testid . '</vendorBookID>
                        <author>' . $author . '</author>
                        <title>' . $title . '</title>
                        <publisher>' . $verlag . '</publisher>
                        <subject>' . $product_cat_name . '</subject>
                        <price currency="EUR">' . $price . '</price>
                        <quantity amount="' . $quantity . '"></quantity>
                        <description>' . $description . '</description>
                        <pictureList>
                            <pictureURL>' . $pictrureUrl . '</pictureURL>
                        </pictureList>
                    </Abebook>
                </AbebookList>
            </inventoryUpdateRequest>';

            $headers = array();
            array_push( $headers, "Content-type: text/plain; charset=ISO-8859-1");
            array_push( $headers, "Content-transfer-encoding: 8BIT");


            $ch = curl_init();
            curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);
            curl_setopt($ch, CURLOPT_VERBOSE, true);
            curl_setopt($ch, CURLOPT_STDERR, $out);
            curl_setopt($ch, CURLOPT_SSLVERSION, 6); 
            curl_setopt($ch, CURLOPT_PORT , 10027);
            curl_setopt($ch, CURLOPT_URL,$url);
            curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
            curl_setopt($ch, CURLOPT_TIMEOUT, 10);
            curl_setopt($ch, CURLOPT_POSTFIELDS, $post_string);

            //curl_setopt($ch, CURLOPT_CUSTOMREQUEST, $post_string);

            $data = curl_exec($ch); 
            $out = fopen('php://output', 'w');
            if(curl_errno($ch))
               error_log(curl_error($ch));
            else
                curl_close($ch);
            $oXML = new SimpleXMLElement($data);
            fclose($out);
            $debug = ob_get_clean();

        foreach($oXML->entry as $oEntry){
                 error_log( $oEntry->requestError . "\n");
                }



        error_log( $debug);
        error_log($data);

我还尝试在调试日志中显示HTTP POST的某些信息,它说字符集为ISO-8859-1。但这似乎不是因为如果这样,它将在Abebooks上正确显示。

有人能发现错误吗?有什么我可以尝试或更改的吗?三天以来,我一直在努力解决这个问题,但仍然找不到我的错误。

谢谢您的时间!

0 个答案:

没有答案
相关问题