为什么我的代码不能用PHP处理?

时间:2021-10-10 20:19:41

I'm super new to this area. for some reason when I put the > symbol anywhere in the code, every bit of code after it is shown as text in the browser. I couldn't find the answer anywhere.

我是这个地区的新手。出于某种原因,当我把>符号放在代码中的任何地方时,它后面的每一个代码都显示为浏览器中的文本。我到处都找不到答案。

<html>
    <head>
        <title>Site Title</title>
    </head>
    <body>
<?php
$curl = curl_init("https://xboxapi.com/v2/messages");
$headers = array();
$headers[] = 'X-AUTH: key';
$headers[] = 'Content-Type: application/json';


$data = array(
    "to" => "{user}",
    "message" => "test"
);

$json = json_encode($data);


curl_setopt($curl, CURLOPT_HEADER, false);
curl_setopt($curl, CURLOPT_RETURNTRANSFER, true);
curl_setopt($curl, CURLOPT_POST, true);
curl_setopt($curl, CURLOPT_POSTFIELDS, $json);
curl_setopt($curl, CURLOPT_HTTPHEADER, $headers);



$server_output = curl_exec ($curl);

curl_close ($curl);

print  $server_output
?>
    </body>
</html>

1 个解决方案

#1


1  

This would not look great as a comment, so I'm posting here what I got when running the code in a CLI/shell.

作为注释,这看起来不太好,因此我将在这里发布在CLI/shell中运行代码时得到的信息。

<html>
    <head>
        <title>Site Title</title>
    </head>
    <body>
    {"success":false,"error_code":401,
"error_message":"No API Key provided or invalid API Key"}

If I run it using PHP Built In web server..I get

如果我使用在web服务器中构建的PHP运行它。我得到

{"success":false,"error_code":401,"error_message":"No API Key provided or invalid API Key"}

{“成功”:false,“error_code”:401,“error_message”:“没有提供API密钥或无效API密钥”}

Per https://xboxapi.com/documentation if you send a valid user id and key in the header, it should work.

根据https://xboxapi.com/documentation,如果您在头中发送有效的用户id和密钥,它应该可以工作。

#1


1  

This would not look great as a comment, so I'm posting here what I got when running the code in a CLI/shell.

作为注释,这看起来不太好,因此我将在这里发布在CLI/shell中运行代码时得到的信息。

<html>
    <head>
        <title>Site Title</title>
    </head>
    <body>
    {"success":false,"error_code":401,
"error_message":"No API Key provided or invalid API Key"}

If I run it using PHP Built In web server..I get

如果我使用在web服务器中构建的PHP运行它。我得到

{"success":false,"error_code":401,"error_message":"No API Key provided or invalid API Key"}

{“成功”:false,“error_code”:401,“error_message”:“没有提供API密钥或无效API密钥”}

Per https://xboxapi.com/documentation if you send a valid user id and key in the header, it should work.

根据https://xboxapi.com/documentation,如果您在头中发送有效的用户id和密钥,它应该可以工作。