如何发送请求有效载荷与PHP cURL? [英] how to send Request Payload with php cURL?

查看:203
本文介绍了如何发送请求有效载荷与PHP cURL?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何使用php cURL发送Request Payload?



我试图将文件上传到服务器,该服务器免费托管文件,并且在将文件发送给curl不是我接受它,我重定向到一个错误页面,当我从你的Interfas做到这一点,我可以看到如何在代码检查器发送文件



我应该如何为文件服务器设置cURL php如同浏览器一样以这种方式接收到我的请求有效载荷


$ b

------ WebKitFormBoundary0cHZePmuSA0mtcdO

内容处理:form-data;名称= 文件[];文件名=vlcsnap-2015-07-17-22h57m13s909.png
Content-Type:image / png
$ b ------ 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);


解决方案

您可以在名称前使用@符号上传和卷曲的文件将从您的服务器上传。

  $ 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);


how to send Request Payload with php cURL?

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

How should I set cURL php for the file server receives me this way as if the browser?

Request Payload

------WebKitFormBoundary0cHZePmuSA0mtcdO

Content-Disposition: form-data; name="files[]"; filename="vlcsnap-2015-07-17-22h57m13s909.png" Content-Type: image/png

------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.

    $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);

这篇关于如何发送请求有效载荷与PHP cURL?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆