如何发送post请求

如何发送post请求,第1张

PHP发送POST请求的三种方式 分别使用curl file_get_content fsocket 来实现post提交数据
代码:
class Request{

public static function post($url, $post_data = '', $timeout = 5){//curl

$ch = curl_init();

curl_setopt ($ch, CURLOPT_URL, $url);

curl_setopt ($ch, CURLOPT_POST, 1);

if($post_data != ''){

curl_setopt($ch, CURLOPT_POSTFIELDS, $post_data);

}

curl_setopt ($ch, CURLOPT_RETURNTRANSFER, 1);

curl_setopt ($ch, CURLOPT_CONNECTTIMEOUT, $timeout);

curl_setopt($ch, CURLOPT_HEADER, false);

$file_contents = curl_exec($ch);

curl_close($ch);

return $file_contents;

}
public static function post2($url, $data){//file_get_content
$postdata = >在网上找资源时,踩了一个坑。网上是这么说的:

用a标签post提交表单

结果我给form表单写的id是 0a , 结果不起作用。后来发现原来id的名字第一个字符不能是数字,之后改成 a0 就行了。


怎么用>

欢迎分享,转载请注明来源:内存溢出

原文地址: https://outofmemory.cn/yw/13407642.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2023-07-30
下一篇 2023-07-30

发表评论

登录后才能评论

评论列表(0条)

保存