php如何请求json数据给java写的接口

浏览:2141 发布日期:2017/07/18 分类:求助交流
我用php提交java写的接口,我用以下代码提交,老是取不到code的值,请问我应该怎么写post请求呢?    $url ='http://192.168.1.108:8080/CommunityStoreAPI/CallDataCenter';
    $data = array(      
        'code'=>'5456sdafsdf555'     
    );      
    function http_post_data($url, $data_string) {    
        $ch = curl_init();
        curl_setopt($ch, CURLOPT_POST, 1);
        curl_setopt($ch, CURLOPT_URL, $url);
        curl_setopt($ch, CURLOPT_POSTFIELDS, $data_string);
        curl_setopt($ch, CURLOPT_HTTPHEADER, array(
            'Content-Type: application/json; charset=utf-8',
            'Content-Length: ' . strlen($data_string))
            );
        ob_start();
        curl_exec($ch);
        $return_content = ob_get_contents();
        ob_end_clean();    
        $return_code = curl_getinfo($ch, CURLINFO_HTTP_CODE);
        return array($return_code, $return_content);
    }    
    $data = json_encode($data);    
    list($return_code, $return_content) = http_post_data($url, $data);    
    var_dump($return_content);
最佳答案
评论() 相关
后面还有条评论,点击查看>>