在 PHP Curl 中发布数据

发布于 2024-12-15 04:17:46 字数 1689 浏览 0 评论 0原文

我正在尝试使用 PHP CURL 将文件中的内容作为参数发布。

数据已发布,但 Zoho 打开一个空白文档,而不是我尝试打开的文档。

我相信这是因为我向 $post_data['content'] 变量提供了无效输入。

$post_data['content'] = "@/c:/xampp/htdocs/site/a.doc";

当收到的内容为空时,Zoho 将根据其内容显示打开一个空白文档佐霍API。

下面给出我的代码供参考。 <

?php   
        $post_data['content']  = "@/c:/xampp/htdocs/site/a.doc";
        $post_data['apikey']   = '[MY API KEY IS HERE]';
        $post_data['output']   = 'url';
        $post_data['filename'] = "a.doc";
        $post_data['id']       = '12345678';
        $post_data['format']   = "doc";
        $post_data['saveurl']  = 'https://localhost/researchPortal/tmp/save.php';
        $post_data['agentname'] = 'ZRemoteAgent';
        $post_data['mode']   = "normaledit";

        foreach ( $post_data as $key => $value)
        {
            $post_items[] = $key . '=' . $value;
        }

        $post_string = implode ('&', $post_items);



    //create cURL connection
$curl_connection =  curl_init('https://exportwriter.zoho.com/remotedoc.im');

//set options
curl_setopt($curl_connection, CURLOPT_CONNECTTIMEOUT, 30);
curl_setopt($curl_connection, CURLOPT_USERAGENT,  "Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1)");
curl_setopt($curl_connection, CURLOPT_RETURNTRANSFER, true);
curl_setopt($curl_connection, CURLOPT_SSL_VERIFYPEER, false);
curl_setopt($curl_connection, CURLOPT_FOLLOWLOCATION, 1);

//set data to be posted
curl_setopt($curl_connection, CURLOPT_POSTFIELDS, $post_string);

//perform our request
$result = curl_exec($curl_connection);

                echo $result;

//close the connection
curl_close($curl_connection);

?>

I am trying to post the content in a file as a param using PHP CURL.

The data gets posted but Zoho opens a blank document instead of the one I'm trying to open.

I believe its because I am providing invalid input the $post_data['content'] variable.

$post_data['content'] = "@/c:/xampp/htdocs/site/a.doc";

Zoho opens a blank document when the content received is empty according to what it says in the ZOHO API.

My code is given below for reference.
<

?php   
        $post_data['content']  = "@/c:/xampp/htdocs/site/a.doc";
        $post_data['apikey']   = '[MY API KEY IS HERE]';
        $post_data['output']   = 'url';
        $post_data['filename'] = "a.doc";
        $post_data['id']       = '12345678';
        $post_data['format']   = "doc";
        $post_data['saveurl']  = 'https://localhost/researchPortal/tmp/save.php';
        $post_data['agentname'] = 'ZRemoteAgent';
        $post_data['mode']   = "normaledit";

        foreach ( $post_data as $key => $value)
        {
            $post_items[] = $key . '=' . $value;
        }

        $post_string = implode ('&', $post_items);



    //create cURL connection
$curl_connection =  curl_init('https://exportwriter.zoho.com/remotedoc.im');

//set options
curl_setopt($curl_connection, CURLOPT_CONNECTTIMEOUT, 30);
curl_setopt($curl_connection, CURLOPT_USERAGENT,  "Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1)");
curl_setopt($curl_connection, CURLOPT_RETURNTRANSFER, true);
curl_setopt($curl_connection, CURLOPT_SSL_VERIFYPEER, false);
curl_setopt($curl_connection, CURLOPT_FOLLOWLOCATION, 1);

//set data to be posted
curl_setopt($curl_connection, CURLOPT_POSTFIELDS, $post_string);

//perform our request
$result = curl_exec($curl_connection);

                echo $result;

//close the connection
curl_close($curl_connection);

?>

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

兮子 2024-12-22 04:17:46

我的猜测是将

curl_setopt($curl_connection, CURLOPT_POSTFIELDS, $post_string);

更改为

curl_setopt($curl_connection, CURLOPT_POSTFIELDS, $post_data);

我猜将其转换为字符串是使curl不使用magic@上传文件
http://dtbaker.com.au /random-bits/uploading-a-file-using-curl-in-php.html

My guess would be change

curl_setopt($curl_connection, CURLOPT_POSTFIELDS, $post_string);

to

curl_setopt($curl_connection, CURLOPT_POSTFIELDS, $post_data);

Im guessing converting it into a string is making curl not upload the file with the magic @
http://dtbaker.com.au/random-bits/uploading-a-file-using-curl-in-php.html

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文