提交带有PHP cURL-400错误的Google Search Appliance(GSA)内容提要

提交带有PHP cURL-400错误的Google Search Appliance(GSA)内容提要,php,curl,google-search-appliance,Php,Curl,Google Search Appliance,因此,我正在尝试为我的web应用程序开发一个模块,它使用PHP cURL将内容提要推送到我们的Google搜索设备(GSA),通过端口19900将数据作为POST信息传输到该设备。根据我在创建提要并向GSA提交提要的文档中所读到的所有内容,这应该可以正常工作,但服务器返回时出现以下错误(非常模糊,基本上没有用处): 那是个错误 您的客户端发出了格式错误或非法的请求。我们只知道这些 我一直在和帮助在我们姐妹站点上安装GSA的架构师一起解决这个问题,我们无法确定是什么导致了我们的问题。据我们的IT部

因此,我正在尝试为我的web应用程序开发一个模块,它使用PHP cURL将内容提要推送到我们的Google搜索设备(GSA),通过端口19900将数据作为POST信息传输到该设备。根据我在创建提要并向GSA提交提要的文档中所读到的所有内容,这应该可以正常工作,但服务器返回时出现以下错误(非常模糊,基本上没有用处):

  • 那是个错误
  • 您的客户端发出了格式错误或非法的请求。我们只知道这些

    我一直在和帮助在我们姐妹站点上安装GSA的架构师一起解决这个问题,我们无法确定是什么导致了我们的问题。据我们的IT部门称,所有端口都已打开,以便进行此通信(如果关闭,我们将不会收到错误消息),并且我们已验证发送服务器的IP地址在GSA中被列为“允许”。不用说,我们被难住了

    以下是传输XML提要的代码:

    <?php
    $target_url = 'http://gsadomain.com:19900/xmlfeed';
    
    $header = array('Content-Type: multipart/form-data');
    
    $fields = array(
        'feedtype'=>'incremental',
        'datasource'=>'datasourcename',
        'data'=>'@'.realpath('gsa_feed.xml')
    );
    
    $ch = curl_init();
    
    curl_setopt($ch, CURLOPT_USERPWD, "gsaadmin:gsaadminpassword");
    curl_setopt($ch, CURLOPT_HTTPHEADER,$header);
    curl_setopt($ch, CURLOPT_TIMEOUT,120);
    curl_setopt($ch, CURLOPT_URL,$target_url);
    curl_setopt($ch, CURLOPT_POST,1);
    curl_setopt($ch, CURLOPT_RETURNTRANSFER,1);
    curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
    curl_setopt($ch, CURLOPT_POSTFIELDS, http_build_query($fields));
    
    $return = curl_exec($ch);
    
    if (curl_errno($ch)) {
        $msg = curl_error($ch);
    }
    
    curl_close ($ch);
    
    echo $return;
    ?>
    
    
    
    下面是我们试图提交的XML:

    <?xml version="1.0" encoding="UTF-8"?>
    <!DOCTYPE gsafeed PUBLIC "-//Google//DTD GSA Feeds//EN" "http://this.is.the.ip/gsafeed.dtd">
    <gsafeed>
        <header>
            <datasource>datasource</datasource>
            <feedtype>incremental</feedtype>
        </header>
        <group>
            <record url="http://website.com/mod/view.php?id=15903" mimetype="text/html" last-modified="Thu, 14 Aug 2014 18:53:00 GMT">
                <acl inheritance-type="and-both-permit">
                    <principal scope="group" access="permit" namespace="Default" case-sensitivity-type="everything-case-insensitive">customers</principal>
                    <principal scope="group" access="permit" namespace="Default" case-sensitivity-type="everything-case-insensitive">partners</principal>
                    <principal scope="group" access="permit" namespace="Default" case-sensitivity-type="everything-case-insensitive">employees</principal>
                </acl>
                <metadata>
                    <meta name="type" content="module" />
                    <meta name="id" content="1" />
                    <meta name="name" content="Module for Everyone" />
                    <meta name="course_id" content="655" />
                </metadata>
                <content>
                    This is the description of the Module for Everyone.
            </content>
            </record>
            <record url="http://website.com/mod/view.php?id=15904" mimetype="text/html" last-modified="Thu, 14 Aug 2014 18:53:00 GMT">
                <acl inheritance-type="and-both-permit">
                    <principal scope="group" access="permit" namespace="Default" case-sensitivity-type="everything-case-insensitive">employees</principal>
                    <principal scope="group" access="permit" namespace="Default" case-sensitivity-type="everything-case-insensitive">partners</principal>
                </acl>
                <metadata>
                    <meta name="type" content="module" />
                    <meta name="id" content="2" />
                    <meta name="name" content="Module for Partners" />
                    <meta name="course_id" content="655" />
                </metadata>
                <content>
                    This is the description of the Module for Partners.
            </content>
            </record>
            <record url="http://website.com/mod/view.php?id=15905" mimetype="text/html" last-modified="Thu, 14 Aug 2014 18:53:00 GMT">
                <acl inheritance-type="and-both-permit">
                    <principal scope="group" access="permit" namespace="Default" case-sensitivity-type="everything-case-insensitive">employees</principal>
                </acl>
                <metadata>
                    <meta name="type" content="module" />
                    <meta name="id" content="3" />
                    <meta name="name" content="Module for Employees" />
                    <meta name="course_id" content="655" />
                </metadata>
                <content>
                    This is the description of the Module for Employees.
            </content>
            </record>
            <record url="http://website.com/course/view.php?id=655#section-1" mimetype="text/html" last-modified="Thu, 14 Aug 2014 18:53:00 GMT">
                <acl inheritance-type="and-both-permit">
                    <principal scope="group" access="permit" namespace="Default" case-sensitivity-type="everything-case-insensitive">customers</principal>
                    <principal scope="group" access="permit" namespace="Default" case-sensitivity-type="everything-case-insensitive">partners</principal>
                    <principal scope="group" access="permit" namespace="Default" case-sensitivity-type="everything-case-insensitive">employees</principal>
                </acl>
                <metadata>
                    <meta name="type" content="topic" />
                    <meta name="id" content="1" />
                    <meta name="name" content="Course Topic for Everyone" />
                    <meta name="course_id" content="655" />
                </metadata>
                <content>
                    This is the description of the Course Topic for All Audiences.
            </content>
            </record>
            <record url="http://website.com/course/view.php?id=655#section-2" mimetype="text/html" last-modified="Thu, 14 Aug 2014 18:53:00 GMT">
                <acl inheritance-type="and-both-permit">
                    <principal scope="group" access="permit" namespace="Default" case-sensitivity-type="everything-case-insensitive">employees</principal>
                    <principal scope="group" access="permit" namespace="Default" case-sensitivity-type="everything-case-insensitive">partners</principal>
                </acl>
                <metadata>
                    <meta name="type" content="topic" />
                    <meta name="id" content="2" />
                    <meta name="name" content="Course Topic for Partners" />
                    <meta name="course_id" content="655" />
                </metadata>
                <content>
                    This is the description of the Course Topic for Partners.
            </content>
            </record>
            <record url="http://website.com/course/view.php?id=655#section-3" mimetype="text/html" last-modified="Thu, 14 Aug 2014 18:53:00 GMT">
                <acl inheritance-type="and-both-permit">
                    <principal scope="group" access="permit" namespace="Default" case-sensitivity-type="everything-case-insensitive">employees</principal>
                </acl>
                <metadata>
                    <meta name="type" content="topic" />
                    <meta name="id" content="3" />
                    <meta name="name" content="Course Topic for Employees" />
                    <meta name="course_id" content="655" />
                </metadata>
                <content>
                    This is the description of the Course Topic for Employees.
            </content>
            </record>
            <record url="http://website.com/course/view.php?id=655" mimetype="text/html" last-modified="Thu, 14 Aug 2014 18:53:00 GMT">
                <acl inheritance-type="and-both-permit">
                    <principal scope="group" access="permit" namespace="Default" case-sensitivity-type="everything-case-insensitive">customers</principal>
                    <principal scope="group" access="permit" namespace="Default" case-sensitivity-type="everything-case-insensitive">partners</principal>
                    <principal scope="group" access="permit" namespace="Default" case-sensitivity-type="everything-case-insensitive">employees</principal>
                </acl>
                <metadata>
                    <meta name="type" content="course" />
                    <meta name="id" content="655" />
                    <meta name="name" content="Course for Everyone" />
                    <meta name="course_id" content="655" />
                </metadata>
                <content>
                    This is the description of the Course for Everyone.
            </content>
            </record>
            <record url="http://website.com/course/view.php?id=656" mimetype="text/html" last-modified="Thu, 14 Aug 2014 18:53:00 GMT">
                <acl inheritance-type="and-both-permit">
                    <principal scope="group" access="permit" namespace="Default" case-sensitivity-type="everything-case-insensitive">employees</principal>
                    <principal scope="group" access="permit" namespace="Default" case-sensitivity-type="everything-case-insensitive">partners</principal>
                </acl>
                <metadata>
                    <meta name="type" content="course" />
                    <meta name="id" content="656" />
                    <meta name="name" content="Course for Partners" />
                    <meta name="course_id" content="656" />
                </metadata>
                <content>
                    This is the description of the Course for Partners.
            </content>
            </record>
            <record url="http://website.com/course/view.php?id=657" mimetype="text/html" last-modified="Thu, 14 Aug 2014 18:53:00 GMT">
                <acl inheritance-type="and-both-permit">
                    <principal scope="group" access="permit" namespace="Default" case-sensitivity-type="everything-case-insensitive">employees</principal>
                </acl>
                <metadata>
                    <meta name="type" content="course" />
                    <meta name="id" content="657" />
                    <meta name="name" content="Course for Employees" />
                    <meta name="course_id" content="657" />
                </metadata>
                <content>
                    This is the description of the Course for Employees.
            </content>
            </record>
        </group>
    </gsafeed>
    
    
    数据源
    增量的
    


    编辑2:成功!见下面我的答案。关键是让cURL处理$fields数组的编码,并传递文件内容,而不仅仅是文件路径。

    我不熟悉GSA API,但似乎您实际上没有发送任何XML数据。为
    数据
    参数发送的字符串值类似于
    @/path/to/gsa_feed.xml
    。我想您实际上需要发布XML,对吗

    也许更像

    $fields = array(
        'feedtype'=>'incremental',
        'datasource'=>'datasourcename',
        'data'=> file_get_contents(realpath('gsa_feed.xml'))
    );
    

    因此,长话短说,我能够正确地提交提要,这一切都与cURL如何处理数据有关。无论是我,还是与我一起工作试图提交提要的工程师,都没有太多的PHP cURL插件经验,也没有太多如何让GSA接受输入字段的经验。部分感谢、the、the和Mike的帮助,我产生了以下代码:

    <?php
    $target_url = 'http://gsadomain.com:19900/xmlfeed';
    
    $header = array('Content-Type: multipart/form-data');
    
    $fields = array(
        'feedtype'=>'incremental',
        'datasource'=>'datasourcename',
        'data'=>file_get_contents(realpath('gsa_feed.xml'))
    );
    
    $ch = curl_init();
    
    curl_setopt($ch, CURLOPT_USERPWD, "gsaadmin:gsaadminpassword");
    curl_setopt($ch, CURLOPT_HTTPHEADER,$header);
    curl_setopt($ch, CURLOPT_TIMEOUT,120);
    curl_setopt($ch, CURLOPT_URL,$target_url);
    curl_setopt($ch, CURLOPT_POST,1);
    curl_setopt($ch, CURLOPT_RETURNTRANSFER,1);
    curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
    curl_setopt($ch, CURLOPT_POSTFIELDS, $fields);
    
    $return = curl_exec($ch);
    
    if (curl_errno($ch)) {
        $msg = curl_error($ch);
    }
    
    curl_close ($ch);
    
    echo $return;
    ?>
    
    
    
    困难在于http_build_query()方法,该方法试图为它执行cURL的工作,并且没有正确设置POST数据的边界


    我们后来在XML中的一些字段上也遇到了一些困难,但这主要是因为我们忘记了用str_替换符号、单引号和双引号。一旦这些都处理好了,XML就被正确地解析了,我们让所有的东西都运行起来。

    我只是试了一下,没有任何运气。所讨论的PHP脚本构建xml文件,因此最初,我只是将写入文件的字符串作为“$fields=array”('fieldtype'=>'incremental','datasource'=>'datasourcename','data'=>$string);”当这不起作用时,我切换到@path/to/gsa_feed.xml方法(考虑到我在文档中看到的内容,您的建议可能正是我想要的。@JoshC您可以在您的问题中链接API文档。从您展示的PHP中,没有任何地方可以构建XML文件。您展示的只是一个简单的带有几个数据字段的cURL POST,其中一个字段是this string in question。这里没有任何其他功能。@Mark Brant我刚刚编辑了原始帖子,其中包含了指向谷歌开发者指南的链接。不幸的是,它在设置自己的提要脚本方面没有提供太多指导。这里是链接: