Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/297.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发出http请求并获取响应_Php_Http - Fatal编程技术网

如何使用php发出http请求并获取响应

如何使用php发出http请求并获取响应,php,http,Php,Http,我第一次使用php处理http请求和响应 这就是我应该在php中添加的请求 GET /items?$filter=ia_itemid+eq+5 HTTP/1.1 Authorization: IC-TOKEN Credential=127896438762198746123 Host: https://api.certicasolutions.com Accept: */* 我应该得到以下回应 { "completed": true, "totalItems": 1, "items

我第一次使用php处理http请求和响应 这就是我应该在php中添加的请求

GET /items?$filter=ia_itemid+eq+5 HTTP/1.1
Authorization: IC-TOKEN Credential=127896438762198746123
Host: https://api.certicasolutions.com
Accept: */*
我应该得到以下回应

{
  "completed": true,
  "totalItems": 1,
  "items": [
    {
      "ia_biserial": "",
      "ia_bloomstaxonomy": "Understanding",
      "ia_contentfocus": "",
      "ia_correctanswer": "A",
      "ia_difficulty": "Medium",
      "ia_dok": "I",
      "ia_gradelevel": "Grade 04",
      "ia_hasimages": "True",
      "ia_itemid": 5,
      "ia_pointvalue": "1",
      "ia_pvalue": "",
      "ia_subject": "Language Arts",
      "ia_teitype": "MC",
      "ia_vendorid": "i-274619",
      "passages": [
        {
          "pa_author": "Susie Post-Rust",
          "pa_commissionedstatus": "Prev. Published",
          "pa_contentarea": "N/A",
          "pa_copyrightowner": "National Geographic Society",
          "pa_copyrightyear": "2002",
          "pa_ethnicity": "Unknown",
          "pa_fleschkincaid": "3.9",
          "pa_gender": "Female(s)",
          "pa_lexile": "780L",
          "pa_multicultural": "No",
          "pa_passageid": "4",
          "pa_passagesource": "Certica Solutions, Inc. Items",
          "pa_passagesourcetitle": "World Dare to Explore Magazine",
          "pa_passagestimulus": "Reading",
          "pa_passagetitle": "Trail Mix",
          "pa_textsubtype": "Other",
          "pa_texttype": "Literary Nonfiction",
          "pa_vendorid": "p-2723",
          "pa_wordcount": "401-600"
        }
      ],
      "standards": [
        {
          "std_code": "CCSS.ELA-Literacy.L.4.5c",
          "std_document": "CC",
          "std_subject": "ELA"
        },
        {
          "std_code": "4.14",
          "std_document": "MA",
          "std_subject": "ELA"
        },
        {
          "std_code": "R.3.b",
          "std_document": "NY",
          "std_subject": "ELA"
        }
      ]
    }
  ],
  "itemFields": [
    "ia_biserial",
    "ia_bloomstaxonomy",
    "ia_contentfocus",
    "ia_correctanswer",
    "ia_difficulty",
    "ia_dok",
    "ia_gradelevel",
    "ia_hasimages",
    "ia_itemid",
    "ia_pointvalue",
    "ia_pvalue",
    "ia_subject",
    "ia_teitype",
    "ia_vendorid",
    "passages",
    "standards"
  ],
  "passageFields": [
    "pa_author",
    "pa_commissionedstatus",
    "pa_contentarea",
    "pa_copyrightowner",
    "pa_copyrightyear",
    "pa_ethnicity",
    "pa_fleschkincaid",
    "pa_gender",
    "pa_lexile",
    "pa_multicultural",
    "pa_passageid",
    "pa_passagesource",
    "pa_passagesourcetitle",
    "pa_passagestimulus",
    "pa_passagetitle",
    "pa_textsubtype",
    "pa_texttype",
    "pa_vendorid",
    "pa_wordcount"
  ],
  "standardFields": [
    "std_code",
    "std_document",
    "std_subject"
  ]
}
请让我知道我应该做什么以及如何做

提前感谢

您可以使用PHP发出http请求。下面的代码使用正确的标题生成您描述的请求

<?php
$crl = curl_init("https://httpbin.org/get?\$filter=ia_itemid+eq+5");

$header = array();
$header[] = 'Authorization: IC-TOKEN Credential=127896438762198746123';
$header[] = 'Accept: */*';

curl_setopt($crl, CURLOPT_HTTPHEADER,$header);
$rest = curl_exec($crl);

curl_close($crl);

print_r($rest);

?>

我使用的是,您可以检查请求的标题和其他参数。

您可以使用PHP进行http请求。下面的代码使用正确的标题生成您描述的请求

<?php
$crl = curl_init("https://httpbin.org/get?\$filter=ia_itemid+eq+5");

$header = array();
$header[] = 'Authorization: IC-TOKEN Credential=127896438762198746123';
$header[] = 'Accept: */*';

curl_setopt($crl, CURLOPT_HTTPHEADER,$header);
$rest = curl_exec($crl);

curl_close($crl);

print_r($rest);

?>

我使用的是,您可以检查请求的标题和其他参数