php如何调用jsp的页面返回结果,最好给个示例代码,谢谢了

主要程序是php的,加个接口是java的,现在要整合到一起,提供了jsp的页面,如何在php中加代码调用呢

楼主好:
我这边有已经用了很久的curl_exec的方法了。我把方法的源码发给你
function make_request($url, $params , $timeout =30){
set_time_limit(0);
$str="";
if($params!="")
{
foreach ($params as $k=>$v) {
if (is_array($v)) {
foreach ($v as $kv => $vv) {
$str .= '&' . $k . '[' . $kv . ']=' . urlencode($vv);
}
} else {
$str .= '&' . $k . '=' . urlencode($v);
}
}
}
if (function_exists('curl_init')) {
// Use CURL if installed...
$ch = curl_init();
$header=array(
'Accept-Language: zh-cn',
'Connection: Keep-Alive',
'Cache-Control: no-cache'
);
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_POSTFIELDS, $str);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_HTTPHEADER, $header);
if($timeout > 0)curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, $timeout);
$result = curl_exec($ch);
$errno = curl_errno($ch);
curl_close($ch);
return $result;
} else {
$context = array(
'http' => array(
'method' => 'POST',
'header' => 'Content-type: application/x-www-form-urlencoded'."\r\n".
'Content-length: ' . strlen($str),
'content' => $str));
if($timeout > 0)$context['http']['timeout'] = $timeout;
$contextid = stream_context_create($context);
$sock = @fopen($url, 'r', false, $contextid);
if ($sock) {
$result = '';
while (!feof($sock)) {
$result .= fgets($sock, 8192);
}
fclose($sock);
}
else{
return 'TimeOut';
}
}
return $result;
}
3个参数:
1 你要访问的页面的url地址。
2 你的请求参数:array(id=>"1",name=>'root'); 按照这样的类型
3 超时时间 默认30秒 很好用的
望楼主采纳为最佳答案吧。这个方法我的项目中一直在用的。
温馨提示:答案为网友推荐,仅供参考
第1个回答  2012-06-28
使用curl就可以了,具体看看php手册,里面有curl实例代码,程序这东西自己摸索的比较好,别人的东西永远都只是别人的!

相关了解……

你可能感兴趣的内容

本站内容来自于网友发表,不代表本站立场,仅表示其个人看法,不对其真实性、正确性、有效性作任何的担保
相关事宜请发邮件给我们
© 非常风气网