PHP framework calls the Java backend, the argument is not passed over the problem solved

Source: Internet
Author: User
Tags php framework
This article to share the content is the PHP framework call Java backend, parameter delivery is not the past problem solving, has a certain reference value, the need for friends can refer to


 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 = $reques Turl. (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 ' = = $req        Uesturl, ' ret ' = $ret, ' http ' = $info,));        Curl_close ($ch);    return $ret; }



System. out. println ("Content Type:" + request. getContentType ());

The Content Type passed before this method is text/html

After the value is removed, empty, passing the past default value of application/x-www-form-urlencoded

You can do it.

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.