使用类Zend_Http_Client

时间:2019-07-17 14:55:10

标签: http zend-framework request client put

使用PUT请求调用HTTP方法时遇到了一些麻烦,因为这些数据根本没有更改。

我或多或少已经成功地处理了GET,OPTIONS这些请求,以便我可以毫无问题地读取数据。但是我还没有找到一种方法来将更改后的数据放入URL地址。参数“ link7”仍然保持不变,这是错误的。

数据示例: {"link1":{"link2":[{"link3":{"link4":[{"link5":{"link6":[{"link7":5}]}}]}}]}}

$url = "http://localhost/api/my-test-data";
$client = new Zend_Http_Client();
$client->setUri($url);
$body = $client->request(\Zend_Http_Client::GET)->getBody();
$data = json_decode($body, true);

$data['link1']['link2'][0]['link3']['link4'][0]['link5']['link6'][0]['link7'] = 1;

$data = Zend_Json::encode($data);
$client->setHeaders('Content-type: application/json');
$client->setRawData($data, 'application/json');
$response = $client->request(\Zend_Http_Client::PUT);

$status = $response->getStatus();
$body = $response->getBody();

在我的文件httpd-userdir.conf中,我具有以下设置:

<Directory "C:/Users/*/My Documents/My Website">
    AllowOverride FileInfo AuthConfig Limit Indexes
    Options MultiViews Indexes SymLinksIfOwnerMatch IncludesNoExec
    Require method GET POST OPTIONS

    <Limit HEAD GET POST PUT DELETE OPTIONS>
        Order deny,allow
        Deny from all
        Allow from localhost
    </Limit>
    <LimitExcept HEAD GET POST PUT DELETE OPTIONS>
        Order deny,allow
        Deny from all
    </LimitExcept>
</Directory>

我希望调用PUT请求后必须更改URL中的数据。 参数“ link7”必须包含1而不是5。

感谢您的帮助。我很感激。

0 个答案:

没有答案