java方法:public void test() {
String a="1239129887493485094385094385";

ServletActionContext.getResponse().setHeader("a", a);

}php代码:
function http($url, $postfields = NULL, $headers = array()) {
$this->http_info = array();
$ci = curl_init();
/* Curl settings */
curl_setopt($ci, CURLOPT_HTTP_VERSION, CURL_HTTP_VERSION_1_0);
curl_setopt($ci, CURLOPT_USERAGENT, $this->useragent);
curl_setopt($ci, CURLOPT_CONNECTTIMEOUT, $this->connecttimeout);
curl_setopt($ci, CURLOPT_TIMEOUT, $this->timeout);
curl_setopt($ci, CURLOPT_RETURNTRANSFER, TRUE);
curl_setopt($ci, CURLOPT_ENCODING, "");
curl_setopt($ci, CURLOPT_SSL_VERIFYPEER, $this->ssl_verifypeer);
curl_setopt($ci, CURLOPT_HEADERFUNCTION, array($this, 'getHeader'));
curl_setopt($ci, CURLOPT_HEADER, FALSE);
curl_setopt($ci, CURLOPT_POST, TRUE);
if (!empty($postfields)) {
curl_setopt($ci, CURLOPT_POSTFIELDS, $postfields);
$this->postdata = $postfields;
}

$headers[] = "API-RemoteIP: " . $_SERVER['REMOTE_ADDR'];
curl_setopt($ci, CURLOPT_URL, $url );
curl_setopt($ci, CURLOPT_HTTPHEADER, $headers );
curl_setopt($ci, CURLINFO_HEADER_OUT, TRUE ); $response = curl_exec($ci);
curl_close ($ci);
return $response;
}
对php语法不熟悉,请教高手指点怎么获取java方法中返回的1239129887493485094385094385这个字符串。
java方法是调到了!就是不知道如何在php中返回head中的值。
curl_setopt($ci, CURLOPT_HEADERFUNCTION, array($this, 'getHeader'));
还有,这个参数是用来干什么的?

解决方案 »

  1.   

    $inputStream = @file_get_contents('php://input');
    这可以得到你返回的值
    curl_setopt 是php的一个扩展库,使用是需要在php.ini 中配置开启。(PHP 4 >= 4.0.2)
    curl_setopt -- 为CURL调用设置一个选项
    bool curl_setopt (int ch, string option, mixed value)
    curl_setopt()函数将为一个CURL会话设置选项。option参数是你想要的设置,value是这个选项给定的值。