我正在尝试使用PHP的curl发出api请求,并且我想获取json作为响应,但是我一直在获取XML代码。
($i * VALUE)
这在确切的在线常见问题解答页面上有说明:
确切的在线API请求支持两种数据格式:JSON和XML。它们在标题中指定,如下所示:
let storyboard = UIStoryboard(name: "MyStoryboardName", bundle: nil) let destinationVC : SignUpViewController = storyboard.instantiateViewController(withIdentifier: "SignUpViewController") self.present(destinationVC, animated: true, completion: nil)
答案 0 :(得分:1)
我发现了问题Content-Type:application / json用于发布数据并提供有关发送内容的信息。我需要使用Accept:application/json
从REST API获取json数据。
代码:
$curl_Items = curl_init();
curl_setopt_array($curl_Items, array(
CURLOPT_URL => 'https://start.exactonline.nl/api/v1/12345678/logistics/Items?$select=Code,Description',
CURLOPT_RETURNTRANSFER => true,
CURLOPT_ENCODING => "",
CURLOPT_MAXREDIRS => 10,
CURLOPT_TIMEOUT => 30,
CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
CURLOPT_CUSTOMREQUEST => "GET",
CURLOPT_HTTPHEADER => array(
"Accept:application/json",
"Authorization: Bearer $access_token",
"Cache-Control: no-cache",
"Postman-Token: f181bd2f-5621-49ee-b1a5-d9f73a2a8825"
),
));
$ResultItems = curl_exec($curl_Items);
答案 1 :(得分:0)
不知道我是否理解这个问题,但是我是否理解。 然后这可能是您的答案:
<?php
header('Content-Type: application/json');
$myArr = array("John", "Mary", "Peter", "Sally");
echo json_encode($myArr);
?>