The problem that the PHP framework calls the Java backend and the parameters cannot be passed is solved

不言
Release: 2023-03-23 17:16:01
Original
1659 people have browsed it

The content of this article is to share with you the solution to the problem that the PHP framework calls the Java backend and the parameters cannot be passed. It has a certain reference value. Friends in need can refer to it


 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;
    }
Copy after login



## System.

out.println("Content Type: " Request . GetContentType ()); ## This method has previously passed

Content Type

as Text/html The default value is application/x-www-form-urlencoded

.

Related recommendations:

How to install and use the PHP framework slim

The relationship between the PHP framework and CMS

The above is the detailed content of The problem that the PHP framework calls the Java backend and the parameters cannot be passed is solved. For more information, please follow other related articles on the PHP Chinese website!

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!