[英]how to make a http request and get response using php
我是第一次使用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"
]
}
請讓我知道我應該怎么做以及如何做到這一點
提前致謝
您可以使用cURL使用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);
?>
我正在使用httpbin.org,因此您可以檢查請求的標頭和其他參數。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.