模拟表单提交数据php js模拟表单提交( 二 )


}
//推送文件流
public function putPart($param) {
$post_data = https://www.04ip.com/post/static::buildData($param);
$curl = curl_init(static::$url);
curl_setopt($curl, CURLOPT_RETURNTRANSFER, true);
curl_setopt($curl, CURLOPT_POST, true);
curl_setopt($curl, CURLOPT_POSTFIELDS, $post_data);
curl_setopt($curl, CURLOPT_HTTPHEADER, [
"Content-Type: multipart/form-data; boundary=" . static::$delimiter,
"Content-Length: " . strlen($post_data)
]);
$response = curl_exec($curl);
curl_close($curl);
return $response;
}
//编译请求头格式和数据流
private static function buildData($param){
$datahttps://www.04ip.com/post/= '';
$eol = "\r\n";
$upload = $param['media'];
unset($param['media']);
foreach ($param as $name = $content) {
$data .= "--" . static::$delimiter . "\r\n"
. 'Content-Disposition: form-data; name="' . $name . "\"\r\n\r\n"
. $content . "\r\n";
}
$data .= "--" . static::$delimiter . $eol
. 'Content-Disposition: form-data; name="media"; filename="' . $param['filename'] . '"' . "\r\n"
. 'Content-Type:application/octet-stream'."\r\n\r\n";
$data .= $upload . "\r\n";
$data .= "--" . static::$delimiter . "--\r\n";
return $data;
}
根据自己的实际情况稍作修改
【模拟表单提交数据php js模拟表单提交】模拟表单提交数据php的介绍就聊到这里吧,感谢你花时间阅读本站内容,更多关于js模拟表单提交、模拟表单提交数据php的信息别忘了在本站进行查找喔 。

推荐阅读