【发布时间】:2013-12-31 03:58:18
【问题描述】:
我有一个奇怪的问题,一旦我提交了一个代码数组,它似乎丢失了它的密钥。
$data = array(
'title' => array(
'en' => 'en test',
'fr' => 'fr test'
),
'description' => array(
'en' => 'description en',
'fr' => 'description fr'
),
);
try {
$oauth = new OAuth("xxx","xxx",OAUTH_SIG_METHOD_HMACSHA1,OAUTH_AUTH_TYPE_AUTHORIZATION);
$oauth->setToken("xxx","xxx");
// first output of array
echo '<pre>',print_r($data),'</pre>';
$oauth->fetch("http://foobar.com/rest/v1/", $data, OAUTH_HTTP_METHOD_POST , array('Content-Type' => 'application/x-www-form-urlencoded'));
// second output of array
echo '<pre>',print_r($data),'</pre>';
$response_info = $oauth->getLastResponseInfo();
header("Content-Type: {$response_info["content_type"]}");
echo $oauth->getLastResponse();
//print_r($oauth);
} catch(OAuthException $E) {
print_r($E);
echo "Exception caught!\n";
echo "Response: ". $E->lastResponse . "\n";
}
生成的输出
// first output of array
Array
(
[title] => Array
(
[en] => en test
[fr] => fr test
)
[description] => Array
(
[en] => description en
[fr] => description fr
)
)
1
// second output of array
Array
(
[title] => Array
(
[0] => fr test
[1] => en test
)
[description] => Array
(
[0] => description fr
[1] => description en
)
)
如您所见,一旦数据被传递,数组就会发生变化。
查看发送到服务器的 headers,post 数据看起来像
title=fr%20test&title=en%20test&description=description%20fr&description=description%20en
服务器端的 api 似乎不接受任何东西,所以我认为问题可能与发送数组的方式有关。
【问题讨论】: