我在php中构建了一个通用方法来处理我对API的所有请求。但是,我确实遇到了一个我无法理解的问题。在我完成了针对API的几个请求之后,等待大约3分钟curl开始提供错误代码100.并且它一直持续到我重新启动API服务(Build on Grizzly,Java)。
我的方法中是否有任何卷曲配置可能不正确?
感谢您的帮助 方法如下所示:
/**
* This function will handle all server requests
* @param $RequestPath String This variable decide which endpoint will be called on
* @param $Method String GET, POST, PUT, DELETE, OPTIONS
* @param $DataArray Array Data that will be sent to the server
* @param $SessionKey String SessionKey is received if the user have a logged in session.
* @return Array Will send back array based on the JSON response from server
*/
public static function SendRequest($RequestPath, $Method, $DataArray, $SessionKey = null){
/* Import configurations */
$configRest_Security = Config::Security();
/* Build the request URL */
$url = "https://localhost:6010/".$RequestPath;
/* Assign the public Key */
$PublicKey = $configRest_Security["PublicKeyPKCS8"];
/* Encode every array value and add them to the url path */
foreach($DataArray as $value){
$url = $url."/".rawurlencode(stripcslashes($value));
}
$ch = curl_init();
/* Set URI for the request */
curl_setopt($ch, CURLOPT_URL, $url);
/* Set the method of this request */
if($Method == "POST"){
curl_setopt($ch, CURLOPT_POST, true);
}elseif($Method == "PUT"){
curl_setopt($ch, CURLOPT_PUT, true);
}elseif($Method == "DELETE"){
curl_setopt($ch, CURLOPT_CUSTOMREQUEST, $Method);
}elseif($Method == "OPTIONS"){
curl_setopt($ch, CURLOPT_CUSTOMREQUEST, $Method);
}
/* If SessionKey was set, send it with the request */
if(!empty($SessionKey)){
$Authentication = "Basic ".Cipher::Encrypt($SessionKey.":".(time()+5));
}else{
$Authentication = "None";
}
/* Create a HTTP Header */
$header = array(
"Accept: application/json",
"Accept-Charset: utf-8",
"Content-Length: 0",
"Content-Type: application/x-www-form-urlencoded",
"X-PublicKey: ".$PublicKey,
"Authorization: ".$Authentication,
);
/* Set HTTP Header in cURL */
curl_setopt($ch, CURLOPT_HTTPHEADER, $header);
/* Set Timeout */
curl_setopt($ch, CURLOPT_TIMEOUT, 4);
/* Fetch Answer */
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
/* Don't check self signed certificate */
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, FALSE);
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, FALSE);
/* Execute curl command */
$result = curl_exec($ch);
$httpReturnCode = curl_getinfo($ch, CURLINFO_HTTP_CODE);
if($httpReturnCode != 200){
echo "HTTP Error: ".$httpReturnCode;
}
curl_close($ch);
return json_decode($result, true);
}