用php模拟post将一个数组传递到到xxx.jsp,jsp页面能直接获取数组值。
如:php数组数据为:name:abc,pwd:123,email:xxx@xxx.com。
php打包成数组,$arr = arry($name,$pwd,$email);
如何将$arr 数组传递给xxx.jsp?
是传递数组,而不将数组变成字符串 传递。
如:php数组数据为:name:abc,pwd:123,email:xxx@xxx.com。
php打包成数组,$arr = arry($name,$pwd,$email);
如何将$arr 数组传递给xxx.jsp?
是传递数组,而不将数组变成字符串 传递。
$arr = array($name,$pwd,$email);
将php的$arr数组post给jsp。
<input name='name' value='abc' />
这样不管在JSP、PHP、还是ASP都可以解析。
{
var $fsk;
public function connect($host, $port)
{
$fsk = @fsockopen($host, $port, $eno, $estr, 10);
if (!$fsk)
{
return false;
}
$this->fsk = $fsk;
return true;
}
public function send($content)
{
fputs($this->fsk, $content);
return true;
}
public function receive()
{
$fsk = $this->fsk;
// header
$buffer = '';
while ( !feof($fsk) )
{
$line = trim(fgets($fsk, 256));
if ('' == $line)
{
break;
}
$buffer .= $line."\n";
}
$header = $buffer; // body
$buffer = '';
if (!$fsk || @feof($fsk))
{
$buffer = 'null';
}
else
{
while ( !feof($fsk) )
{
$buffer .= fgets($fsk, 256);
}
}
$body = $buffer; $this->fsk = $fsk;
$return = array(
'header' => $header,
'body' => $body
);
return $return;
}
public function close()
{
fclose($this->fsk);
}
}?>用法
<?php// HTTP数据包内容
$post = <<<package
POST /post/ HTTP/1.1
Accept: */*
Accept-Language: zh-CN
Referer: http://www.uuland.cn/
Content-Type: application/x-www-form-urlencoded
Content-Length: xx
Accept-Encoding: gzip, deflate
User-Agent: Mozilla/4.0 (compatible; MSIE 8.0; Windows NT 5.1; Trident/4.0; .NET CLR 2.0.50727; .NET CLR 3.0.4506.2152; .NET CLR 3.5.30729)
Host: 127.0.0.1
Connection: Close
Cache-Control: no-cache
Cookie: PHPSSIONID=abcZBkWhZqweFfs-s-kvsdata of post
package;include 'socket.php';
$sck = new socket();
$sck->connect('www.uuland.cn', 80);
$sck->send($post);
$response = $sck->receive();
$sck->close();
unset($sck);
print_r($response);
?>
if (!$fp) {
echo "$errstr ($errno)<br />\n";
} else {
$out = "捕获到的header信息"; fwrite($fp, $out);
while (!feof($fp)) {
echo fgets($fp, 128);
}
fclose($fp);
}