0
我在使用WordPress的wp_remote_post()函數和Redmine的REST API時遇到了問題。 主要問題是,當我嘗試發帖時,我得到了403-禁止的回報。WordPress wp_remote_post()發送信息到Redmine REST API
這是我的工作代碼:
$info = array(
'issue' => array(
'key' => '59930c6460e8e71ef58b4cc95d852153bf21b510',
'subject' => 'New bug from ' . get_bloginfo('name') . ' (' . get_bloginfo('wpurl') . ')',
'project_id' => 10,
'tracker_id' => 1,
'description' => $_POST['bug_contents'],
'custom_fields' => array(
array(
'name' => 'Web Server Version',
'id' => 1,
'value' => $_SERVER['SERVER_SOFTWARE'],
),
array(
'name' => 'PHP Version',
'id' => 2,
'value' => phpversion(),
),
array(
'name' => 'MySQL Version',
'id' => 3,
'value' => $wpdb->get_var("SELECT VERSION() as `version`"),
),
array(
'name' => 'WordPress Version',
'id' => 4,
'value' => $wp_version,
),
array(
'name' => 'WordPress Admin Email',
'id' => 5,
'value' => get_bloginfo('admin_email'),
),
array(
'name' => 'Server IP',
'id' => 6,
'value' => $_SERVER['SERVER_ADDR'],
),
array(
'name' => 'Server External IP',
'id' => 7,
'value' => $ip_feedback_array['origin'],
),
),
),
);
$api_call = wp_remote_post(
'https://ias:[email protected]/issues.json',
array(
'method' => 'POST',
'timeout' => 45,
'redirection' => 5,
'httpversion' => '1.0',
'blocking' => true,
'headers' => array(
'Content-Type' => 'application/json',
//'Authorization' => 'Basic ' . base64_encode('ias' . ':' . '1q2w3e$r'),
'X-Redmine-API-Key' => '59930c6460e8e71ef58b4cc95d852153bf21b510'
),
'cookies' => array(),
'body' => json_encode($info),
)
);
但是我收到的迴應是:
Array
(
[headers] => Array
(
[server] => cloudflare-nginx
[date] => Wed, 30 Apr 2014 15:07:58 GMT
[content-type] => application/json; charset=utf-8
[connection] => close
[set-cookie] => Array
(
[0] => __cfduid=dd5dfb36ec5e73c40e7eb94ba34ab8ece1398870478439; expires=Mon, 23-Dec-2019 23:50:00 GMT; path=/; domain=.14all.me; HttpOnly
[1] => _redmine_session=BAh7BiIPc2Vzc2lvbl9pZCIlOWU4NWRlOWRjMGNiNDczZWI2YzU1NGE2MTlkMTc4NjI%3D--2396b75554bde9fbe8a15870b0e3861687968094; path=/; HttpOnly
[2] => autologin=; path=/; expires=Thu, 01-Jan-1970 00:00:00 GMT
)
[x-runtime] => 0.048408
[cache-control] => no-cache
[x-ua-compatible] => IE=Edge,chrome=1
[x-rack-cache] => invalidate, pass
[x-request-id] => 9dcd72c966f6434914e2b65ae706bb30
[x-powered-by] => Phusion Passenger 4.0.10
[status] => 403 Forbidden
[cf-ray] => 1234a6ea3ce9014b-CDG
[content-encoding] => gzip
)
[body] =>
[response] => Array
(
[code] => 403
[message] => Forbidden
)
[cookies] => Array
(
[0] => WP_Http_Cookie Object
(
[name] => __cfduid
[value] => dd5dfb36ec5e73c40e7eb94ba34ab8ece1398870478439
[expires] => 1577145000
[path] =>/
[domain] => .14all.me
[httponly] =>
)
[1] => WP_Http_Cookie Object
(
[name] => _redmine_session
[value] => BAh7BiIPc2Vzc2lvbl9pZCIlOWU4NWRlOWRjMGNiNDczZWI2YzU1NGE2MTlkMTc4NjI=--2396b75554bde9fbe8a15870b0e3861687968094
[expires] =>
[path] =>/
[domain] => rm.14all.me
[httponly] =>
)
[2] => WP_Http_Cookie Object
(
[name] => autologin
[value] =>
[expires] => 0
[path] =>/
[domain] => rm.14all.me
)
)
[filename] =>
)
我認爲有一個問題,與如何我送的認證參數。任何幫助表示讚賞。