Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/255.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/silverlight/4.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
使用PHP上的curl为web API设置路径HTTP GET请求_Php_Http_Curl_Http Headers_Httprequest - Fatal编程技术网

使用PHP上的curl为web API设置路径HTTP GET请求

使用PHP上的curl为web API设置路径HTTP GET请求,php,http,curl,http-headers,httprequest,Php,Http,Curl,Http Headers,Httprequest,我正在使用teamviewer API开发一个web_应用程序。根据,它使用HTTP请求(GET、POST等)工作 我不知道如何使用CURL在PHP上发出请求。文件中说要做到这一点: POST /api/v1/oauth2/token HTTP/1.1 Host: webapi.teamviewer.com Content-Type: application/x-www-form-urlencoded 所以我写了这个 $url = 'webapi.teamviewer.com'; $heade

我正在使用teamviewer API开发一个web_应用程序。根据,它使用HTTP请求(GET、POST等)工作

我不知道如何使用CURL在PHP上发出请求。文件中说要做到这一点:

POST /api/v1/oauth2/token HTTP/1.1
Host: webapi.teamviewer.com
Content-Type: application/x-www-form-urlencoded
所以我写了这个

$url = 'webapi.teamviewer.com';
$headers = array(
    'GET /api/v1/oauth2/authorize HTTP/1.1',
    'Content-type: application/x-www-form-urlencoded'
);
//data
$data = [
    'response_type' => 'authorization_code',
    'redirect_uri' => 'https%3A%2F%2FTesting%2Ecom%2F',
    'client_id'   => '65671-XDdsxUNyxGmskcJHQgLC'
];

$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_HEADER, true);
curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);
curl_setopt($ch, CURLOPT_POST, false);
curl_setopt($ch, CURLOPT_POSTFIELDS, http_build_query($data));
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
我就是不知道如何通过HTTP/1.1和路径
/api/v1/oauth2/authorize
指示请求。我把球放在头球上,但我肯定它不会去那里


我曾经在嵌入式C上工作,我记得首先连接到主机,然后作为命令写入GET path HTTP/1.1。

您的
$url
应该是完整路径,就像普通url一样。是的

$url = 'webapi.teamviewer.com/api/v1/oauth2/authorize';
您可以从
$headers
中删除
GET…
部分,因为URL(路径)不在其中

在那之后应该可以了。如果要查看有关curl连接的更多信息以及正在进行的操作,请添加以下选项:

curl_setopt($ch, CURLOPT_VERBOSE, true);
卷曲选项的完整列表位于