我有一个项目,客户要求将扫描数据库,将记录表中的各个公司的ID,名称,处理状态通过post发到一个url,这个url对应的php文件要求能处理post数据并返回一个response result(如verify,deny,not commit),我使用的post函数如下:
function do_post_request($id, $url, $data, $optional_headers = null)
{
$params = array('http' => array(
'method' => 'POST',
'content' => $data
));
if ($optional_headers !== null) {
$params['http']['header'] = $optional_headers;
}
$ctx = stream_context_create($params);
$fp = @fopen($url, 'rb', false, $ctx);
if (!$fp) {
//throw new Exception("Problem with $url, $php_errormsg");
$InfoSentLog="Problem with {$url}, remote system is down or internet is down";
$infosql="update personinfo set InfoSentLog='{$InfoSentLog}' where ID={$id}";
mysql_query($infosql);
return false;
}
$response = @stream_get_contents($fp);
if ($response === false) {
//throw new Exception("Problem reading data from $url, $php_errormsg");
$InfoSentLog="Problem reading data from {$url}, remote system is down or internet is down";
$infosql="update personinfo set InfoSentLog='{$InfoSentLog}' where ID={$id}";
mysql_query($infosql);
return false;
}
return $response;
}
}
其中,$response = @stream_get_contents($fp);就是得到服务器处理文件的返回值,如今我怎么写这个处理文件,即如何处理post数据并给一个返回值呢?请大虾们讲一下post响应并返回值的原理,最好有个简单的例子,谢谢!
function do_post_request($id, $url, $data, $optional_headers = null)
{
$params = array('http' => array(
'method' => 'POST',
'content' => $data
));
if ($optional_headers !== null) {
$params['http']['header'] = $optional_headers;
}
$ctx = stream_context_create($params);
$fp = @fopen($url, 'rb', false, $ctx);
if (!$fp) {
//throw new Exception("Problem with $url, $php_errormsg");
$InfoSentLog="Problem with {$url}, remote system is down or internet is down";
$infosql="update personinfo set InfoSentLog='{$InfoSentLog}' where ID={$id}";
mysql_query($infosql);
return false;
}
$response = @stream_get_contents($fp);
if ($response === false) {
//throw new Exception("Problem reading data from $url, $php_errormsg");
$InfoSentLog="Problem reading data from {$url}, remote system is down or internet is down";
$infosql="update personinfo set InfoSentLog='{$InfoSentLog}' where ID={$id}";
mysql_query($infosql);
return false;
}
return $response;
}
}
其中,$response = @stream_get_contents($fp);就是得到服务器处理文件的返回值,如今我怎么写这个处理文件,即如何处理post数据并给一个返回值呢?请大虾们讲一下post响应并返回值的原理,最好有个简单的例子,谢谢!
或支持http1.1自定义的函数,用post方式上传,得到返回值分析就行了
具体搜索下php post 上传