我正在尝试使用输入参数创建一个api路由,但没有得到预期的结果。
这是我的webapi.xml:
<?xml version="1.0"?>
<routes xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="../../../../../app/code/Magento/Webapi/etc/webapi.xsd">
    <route url="/V1/foo" method="POST" secure="true">
        <service class="..\FooInterface"
                 method="getFooById"/>
        <resources>
            <resource ref="anonymous"/>
        </resources>
        <data>
            <parameter name="id" force="true">%id%</parameter>
        </data>
    </route>
</routes>这是我的界面:
interface FooInterface
{
    /**
     * Test function
     *
     * @api
     * @param string $id
     * @return string
     */
    public function getFooById($id);
}这里是班级:
class Foo implements FooInterface
{
    /**
     * {@inheritdoc}
     */
    public function getFooById($id){
        return $id;
    }
}我忽略了带有首选项的di.xml。现在,如果我叫那条路线,我所要做的就是返回%id%。即使我不输入任何参数,我也可以得到它而不是错误或其他信息。
我在这里做错了什么?
我试过了:
- 发送获取请求
- 发送带有参数的获取请求 /order?id=foo
- 发送帖子请求
- 发送带有表单数据的过帐请求
- 发送带有原始数据的帖子请求(如屏幕截图所示)
所有结果都相同-> %id%
我正在使用社区版btw。
                  您有没有找到解决他问题的办法?请让我知道我面临同样的问题,谢谢
                
                
                  
                    —
                    Purushotam Sharma,
                    
                  
                
              
                  抱歉,该公司离开了,无法再访问代码。我认为我做了我在上一个评论中唯一回答中的内容。
                
                
                  
                    —
                    斯特罗斯
                    
                  
                
              
