简体   繁体   English

如何使用php cURL发送Request Payload?

[英]how to send Request Payload with php cURL?

how to send Request Payload with php cURL? 如何使用php cURL发送Request Payload?

I'm trying to upload a file to a server that hosts files for free, and when sending the file to curl not I accept it and I redirected to an error page, and when I do it from your Interfas I can see how the files are sent in code inspector 我正在尝试将文件上传到免费托管文件的服务器,当发送文件卷曲时我不接受它而我重定向到错误页面,当我从你的Interfas那里做的时候我可以看到文件是怎么回事在代码检查员中发送

How should I set cURL php for the file server receives me this way as if the browser? 我应该如何为文件服务器设置cURL php,就像浏览器一样接收我?

Request Payload 请求有效负载

------WebKitFormBoundary0cHZePmuSA0mtcdO ------ WebKitFormBoundary0cHZePmuSA0mtcdO

Content-Disposition: form-data; 内容处理:表格数据; name="files[]"; 名称= “文件[]”; filename="vlcsnap-2015-07-17-22h57m13s909.png" Content-Type: image/png filename =“vlcsnap-2015-07-17-22h57m13s909.png”内容类型:image / png

------WebKitFormBoundary0cHZePmuSA0mtcdO-- ------ WebKitFormBoundary0cHZePmuSA0mtcdO--

$ch = curl_init();

$ch_file = new CURLFile( $tmp_name, $type, $name );
$data = array("files[]"=>$ch_file);

curl_setopt($ch, CURLOPT_URL, "http://url_site.com");
curl_setopt($ch, CURLOPT_POST, true);
curl_setopt($ch, CURLOPT_POSTFIELDS, $data);

$response = curl_exec($ch);

You can use an @ symbol in front of the name of the file to upload and curl will upload it from your server. 您可以在文件名前面使用@符号进行上传,curl将从服务器上传。

    $ch = curl_init("http://url_site.com");
    curl_setopt($ch, CURLOPT_POST,1);
    curl_setopt($ch, CURLOPT_POSTFIELDS, array('files[]' => '@'.$tmp_name));
    curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, FALSE);
    curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
    $result = curl_exec($ch);

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM