jimen
新手上路

UID 86478
精华
0
积分 5
帖子 3
金钱 5 喜悦币
威望 0
人脉 0
阅读权限 10
注册 2007-1-16
状态 离线
|
[广告]: q
m
求高手帮我看看(php通过post方式发送http请求实现上传文件功能)
高分求高手帮我看看下面的一段代码(php通过post方式发送http请求实现上传文件功能)
发送不能成功,希望高手指点,如果有类似的例子请发上来看看,谢谢了!
主要
<?
$others = file_get_contents("weibin.xml");
$length = strlen($others);
$header = "POST /dataReceive.html?formAction=kangQuest HTTP/1.1\r\n"; ##原来少了个“/”
$header .= "Host: www.wujian.com:8081\r\n";
$header .= "Referer: http://www.jimen.com\r\n";
$header .= "User-Agent: Mozilla/4.0\r\n";
$header .= "Content-Disposition: attachment;filename=" . '"weibin.xml"' . "\r\n";
$header .= "Content-Type: multipart/form-data\r\n";
$header .= "Content-Length: ".$length."\r\n";
$header .= "Accept: */*\r\n";
$header .= "\r\n";
$header .= $others."\r\n"; ##POST方式发送不能接在脚本后面
$header .= "\r\n";
echo $header;
//$header .= "Connection: Close\r\n\r\n";
$fp = fsockopen("www.wujian.com",8081,$errno,$errstr,10);
if (!$fp) {
echo "$errstr ($errno)<br />\n";
} else {
echo "连接成功.";
if( $sendCnt = fputs($fp,$header) ){
while (!feof($fp)) {
if($cont = fread($fp, 8192))
{
echo "接收数据成功";
$contents .= $cont;
}else
{
echo "接收数据失败";
}
}
if(!fclose($fp))echo "关闭连接失败1";
echo "contents:".$contents;
}else{
if(!fclose($fp))echo "关闭连接失败2";
echo "发送数据失败!";
}
echo $sendCnt."=".strlen($header);
}
?>
[ 本帖最后由 jimen 于 2008-3-13 04:44 PM 编辑 ]
|
|