I'm use the last w3c api key with php, when i send query by curl for checking HTML data i take this error
array(4) { ["type"]=> string(46) "https://tools.ietf.org/html/rfc2616#section-10" ["title"]=> string(17) "An error occurred" ["status"]=> int(405) ["detail"]=> string(18) "Method Not Allowed" }
$html = '<h1>Hello<a ="hello.html">test<a>';
$curl = curl_init();
curl_setopt_array($curl, array(
CURLOPT_URL => "https://api.w3.org/groups?apikey=mykey",
CURLOPT_RETURNTRANSFER => true,
CURLOPT_ENCODING => "",
CURLOPT_MAXREDIRS => 10,
CURLOPT_TIMEOUT => 30,
CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
CURLOPT_CUSTOMREQUEST => "POST",
CURLOPT_POSTFIELDS => $html,
CURLOPT_HTTPHEADER => array(
"User-Agent: Any User Agent",
"Cache-Control: no-cache",
"Content-type: application/json",
"Access-Control-Allow-Origin: https://my.site",
"Access-Control-Allow-Credentials: true",
"charset: utf-8"
),
));
$response = curl_exec($curl);
$err = curl_error($curl);
curl_close($curl);
if ($err) {
die('ups, error');
}
$result = json_decode($response, true);
var_dump($result);
by api w3c key i have problem, how to resolve it ? in documentation i didn't find this error and just a simple example to use Post html data
$curl = curl_init();
curl_setopt_array($curl, array(
CURLOPT_URL => "https://validator.w3.org/nu/?out=json",
CURLOPT_RETURNTRANSFER => true,
CURLOPT_ENCODING => "",
CURLOPT_MAXREDIRS => 10,
CURLOPT_TIMEOUT => 30,
CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
CURLOPT_CUSTOMREQUEST => "POST",
CURLOPT_POSTFIELDS => '<h1>Hello<a ="hello.html">test<a>',
CURLOPT_HTTPHEADER => array(
"User-Agent: Any User Agent",
"Cache-Control: no-cache",
"Content-Type: text/html",
/* may not use
"Access-Control-Allow-Origin: https://test.com",
"Access-Control-Allow-Credentials: true",
*/
"charset: utf-8"
),
));
$response = curl_exec($curl);
$err = curl_error($curl);
curl_close($curl);
if ($err) {
die('error');
}
$res = json_decode($response, true);
var_dump($res); //return associative array, then u can show it html
a simple example with ajax without curl
<script>
var htmls = '<h1>Hello<a ="hello.html">test<a>';
// easy way to get current pages HTML
jQuery.get('#', function(html) {
// emulate form post
var formData = new FormData();
formData.append('out', 'json');
formData.append('content', htmls);
// make ajax call
$.ajax({
url: "https://html5.validator.nu/", /* https://validator.w3.org/nu/ */
data: formData,
dataType: "json",
type: "POST",
processData: false,
contentType: false,
success: function(data) {
console.log(data.messages); // data.messages is an array
},
error: function() {
console.warn(arguments);
}
});
});
</script>
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.