空请求正在通过Curl发送,并给出500内部服务器错误 [英] Empty request is sending thru Curl that gives 500 Internal Server Error
问题描述
我已经使用curl_setopt_array函数通过curl设置了参数,但是当我打印设置的选项时,例如标头,则表明[header_size] => 0和[request_size] => 0 PFB代码段.
I have set parameters thru curl using curl_setopt_array function but when I print the options that I set e.g. headers then it shows that [header_size] => 0 and [request_size] => 0 PFB the code snippet.
$url='https://mysite.com:443/login';
$headers=array('contentType:application/json','X-API-Key:34SDFSDFvvsdfsdEERER45');
$keyPass="passphrase";
$ret=curl_setopt_array($handle, array(
CURLOPT_SSL_VERIFYPEER => TRUE,
CURLOPT_SSL_VERIFYHOST => 2,
CURLOPT_VERBOSE => TRUE,
CURLOPT_HEADER => TRUE,
CURLOPT_HTTPHEADER => $headers,
CURLOPT_CAINFO => 'C:\wamp\www\server.pem',
//CURLOPT_USERPWD => 'uid=>username,password=>pwd',
CURLOPT_HTTPAUTH => CURLAUTH_BASIC,
CURLOPT_RETURNTRANSFER => TRUE,
CURLOPT_USERAGENT => "Mozilla/5.0 (Windows NT 6.1; rv:26.0) Gecko/20100101 Firefox/26.0",
CURLOPT_POST => TRUE,
CURLOPT_POSTFIELDS => array("uid"=>'username',"password"=>'pwd'),
CURLOPT_FAILONERROR => TRUE,
));
}
if (false==$ret) {
echo "Unable to set curl options";
}
$info=curl_getinfo($handle);
print_R($info);
$response=curl_exec($handle);
$info=curl_getinfo($handle);
print_R($info);
Output after execution
<html>
<title>Consume Rest With Curl</title>
</head>
<body>
Array //request to server
(
[url] => https://mysite.com:443/login
[content_type] =>
[http_code] => 0
[header_size] => 0
[request_size] => 0
[filetime] => 0
[ssl_verify_result] => 0
[redirect_count] => 0
[total_time] => 0
[namelookup_time] => 0
[connect_time] => 0
[pretransfer_time] => 0
[size_upload] => 0
[size_download] => 0
[speed_download] => 0
[speed_upload] => 0
[download_content_length] => -1
[upload_content_length] => -1
[starttransfer_time] => 0
[redirect_time] => 0
[certinfo] => Array
(
)
[primary_ip] =>
[primary_port] => 0
[local_ip] =>
[local_port] => 0
[redirect_url] =>
)
Array //response from server
(
[url] => https://mysite.com:443/login
[content_type] =>
[http_code] => 500
[header_size] => 25
[request_size] => 362
[filetime] => -1
[ssl_verify_result] => 0
[redirect_count] => 0
[total_time] => 0.265
[namelookup_time] => 0
[connect_time] => 0.031
[pretransfer_time] => 0.14
[size_upload] => 248
[size_download] => 0
[speed_download] => 0
[speed_upload] => 935
[download_content_length] => -1
[upload_content_length] => 248
[starttransfer_time] => 0.187
[redirect_time] => 0
[certinfo] => Array
(
)
[primary_ip] => server ip
[primary_port] => 443
[local_ip] => client ip
[local_port] => 50909
[redirect_url] =>
)
Error --> The requested URL returned error: 500 Internal Server Error
</body>
</html>
我想知道何时发出请求,然后shd数组中的所有参数都显示一些值(例如标头大小,请求大小).如果我输入错误或代码有误,请更正我. 我在服务器端验证了这一点,似乎标题已到达服务器,但其他请求参数为空.我只是在邮寄字段"中传递用户名和密码,即正文.
I would like to know when we make request then all the parameters in array shd show some values (e.g. header size, request size). Please correct me if I am wrong or Is there any wrong with the code. I verified this with server side and it seems that the header is reaching to server but other request parameters are empty. I am just passing username and password i.e. body in Post Fields.
Regts
推荐答案
实际上是这样更改这些参数的..
Actually change these parameters like this..
CURLOPT_SSL_VERIFYPEER => FALSE,
CURLOPT_SSL_VERIFYHOST => FALSE,
这篇关于空请求正在通过Curl发送,并给出500内部服务器错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!