本篇文章给大家分享的内容是php框架调用java后端,参数传递不过去的问题解决,有着一定的参考价值,有需要的朋友可以参考一下
public function request($requestURL,$params='',$method ='GET',$contentType='',$user=''){
$timeout = 30;
$ch = null;
if ('POST' === strtoupper($method)) {
$ch = curl_init($requestURL);
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_FRESH_CONNECT, 1);
curl_setopt($ch, CURLOPT_FORBID_REUSE, 1);
if (is_string($params)) {
curl_setopt($ch, CURLOPT_POSTFIELDS, $params);
} else {
curl_setopt($ch, CURLOPT_POSTFIELDS, http_build_query($params));
}
} else if('GET' === strtoupper($method)) {
if(is_string($params)) {
$real_url = $requestURL. (strpos($requestURL, '?') === false ? '?' : ''). $params;
} else {
$real_url = $requestURL. (strpos($requestURL, '?') === false ? '?' : ''). http_build_query($params);
}
$ch = curl_init($real_url);
} else {
$args = func_get_args();
return false;
}
if ($contentType) {
curl_setopt($ch, CURLOPT_HTTPHEADER, array('Content-Type:'.$contentType));
}
if ($user) {
curl_setopt($ch, CURLOPT_USERPWD, $user);
}
curl_setopt($ch, CURLOPT_HEADER, 0);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_TIMEOUT, $timeout);
$ret = curl_exec($ch);
$info = curl_getinfo($ch);
$contents = array(
'httpInfo' => array(
'send' => $params,
'url' => $requestURL,
'ret' => $ret,
'http' => $info,
)
);
curl_close($ch);
return $ret;
}System.out.println("Content Type: " + request.getContentType());
此方法之前传递的Content Type为text/html
后面把传值去掉,为空,传递过去的默认值为application/x-www-form-urlencoded
就可以了。
相关推荐:
立即学习“PHP免费学习笔记(深入)”;
以上就是PHP框架调用Java后端,参数传递不过去的问题解决的详细内容,更多请关注php中文网其它相关文章!
PHP怎么学习?PHP怎么入门?PHP在哪学?PHP怎么学才快?不用担心,这里为大家提供了PHP速学教程(入门到精通),有需要的小伙伴保存下载就能学习啦!
Copyright 2014-2025 https://www.php.cn/ All Rights Reserved | php.cn | 湘ICP备2023035733号