JQuery の $.getJSON 関数から Web サービスを呼び出すと、正常に動作します。
var p = {
'field1': 'value1',
'field2': 'value2',
'field3': 'value3'
};
$.getJSON('https://service:xxx@xxx.xxx.yyyyy.com.xx/service/search?callback=?', p, function(data) {
if (data[0]) {
// print results
} else {
// no results found
}
});
PHP と CURL から接続しようとしていますが、うまくいきません。常に false を返します。
//初挑戦
$params = array( 'field1' => 'value1', 'field2' => 'value2', 'field3'=> 'value3');
$ch = curl_init();
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_URL, 'https://service:xxx@xxx.xxx.yyyyy.com.xx/service/search?callback=?');
curl_setopt($ch, CURLOPT_POSTFIELDS, $params);
$result = curl_exec($ch); // return false instead of my JSON
// 2 回目の試行
$data_string = json_encode($params);
$ch = curl_init('https://https://service:xxx@xxx.xxx.yyyyy.com.xx/service/search?callback=?');
curl_setopt($ch, CURLOPT_CUSTOMREQUEST, "POST");
curl_setopt($ch, CURLOPT_POSTFIELDS, $data_string);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_HTTPHEADER, array(
'Content-Type: application/json',
'Content-Length: ' . strlen($data_string))
);
$result2 = curl_exec($ch); //return false instead of my JSON
私が間違っていることは何ですか?
どうもありがとう、