<?php
function
curlrequest(
$url
,
$data
,
$method
=
'post'
){
$ch
= curl_init();
curl_setopt(
$ch
, CURLOPT_URL,
$url
);
curl_setopt(
$ch
, CURLOPT_RETURNTRANSFER,1);
curl_setopt(
$ch
, CURLOPT_CUSTOMREQUEST,
$method
);
curl_setopt(
$ch
,CURLOPT_HTTPHEADER,
array
(
"X-HTTP-Method-Override: $method"
));
curl_setopt(
$ch
, CURLOPT_POSTFIELDS,
$data
);
$document
= curl_exec(
$ch
);
if
(!curl_errno(
$ch
)){
$info
= curl_getinfo(
$ch
);
echo
'Took '
.
$info
[
'total_time'
] .
' seconds to send a request to '
.
$info
[
'url'
];
}
else
{
echo
'Curl error: '
. curl_error(
$ch
);
}
curl_close(
$ch
);
return
$document
;
}
$url
=
'http://localhost/test/curl.php'
;
$data
=
"request from put method"
;
$return
= curlrequest(
$url
,
$data
,
'put'
);
var_dump(
$return
);
exit
;
?>
请发表评论