使用PUT服务器请求卷曲到php

时间:2022-10-19 18:18:46

I can display the values using GET but i don't know how to use PUT to submit a request that will change the value of my data. here is my code:

我可以使用GET显示值,但我不知道如何使用PUT提交将更改我的数据值的请求。这是我的代码:

 if($visit >= 10){

                    $wh = curl_init();

                curl_setopt($wh, CURLOPT_URL, "https://core.voluum.com/campaigns/" . $id);
                curl_setopt($wh, CURLOPT_RETURNTRANSFER, 1);
                curl_setopt($wh, CURLOPT_CUSTOMREQUEST, "GET");


                $head = array();
                $head[] = "Cwauth-Token: " . $tok;
                curl_setopt($wh, CURLOPT_HTTPHEADER, $head);

                $resulta = curl_exec($wh);
                if (curl_errno($wh)) {
                    echo 'Error:' . curl_error($wh);
                }
                echo "Request:" . "<br>";
                $campinfo = json_decode($resulta, true);
                echo '<pre>' . print_r($campinfo, TRUE) . '</pre>';
                foreach($campinfo['pathsGroups'] as $datacamp){
                    echo $datacamp['active'];

Here is a part of my data:

这是我数据的一部分:

Array
(
    [pathsGroups] => Array
        (
            [0] => Array
                (
                    [condition] => Array
                        (
                            [country] => Array
                                (
                                    [predicate] => MUST_BE
                                    [countryCodes] => Array
                                        (
                                            [0] => IQ
                                        )

                                )

                            [customVariableConditions] => Array
                                (
                                    [0] => Array
                                        (
                                            [predicate] => MUST_NOT_BE
                                            [index] => 0
                                            [texts] => Array
                                                (
                                                    [0] => 
                                                    [1] => Unknown
                                                    [2] => unknown
                                                )

                                            [text] => 
                                        )

                                    [1] => Array
                                        (
                                            [predicate] => MUST_NOT_BE
                                            [index] => 1
                                            [texts] => Array
                                                (
                                                    [0] => Unknown
                                                    [1] => 
                                                    [2] => unknown
                                                )

                                            [text] => Unknown
                                        )

                                    [2] => 
                                    [3] => 
                                    [4] => 
                                    [5] => 
                                    [6] => 
                                    [7] => 
                                    [8] => 
                                    [9] => 
                                )

                        )

                    [paths] => Array
                        (
                            [0] => Array
                                (
                                    [weight] => 100
                                    [active] => 1
                                    [landers] => Array
                                        (
                                            [0] => Array
                                                (
                                                    [lander] => Array
                                                        (
                                                            [id] => 
                                                            [namePostfix] => 
                                                            [name] => Global 
                                                        )

                                                    [weight] => 100
                                                )

                                        )

                                    [offers] => Array
                                        (
                                            [0] => Array
                                                (
                                                    [offer] => Array
                                                        (
                                                            [id] => 
                                                            [name] => 
                                                            [namePostfix] => 
                                                        )

                                                    [weight] => 100
                                                )

                                        )

                                )

                        )

                    [active] => 1 // change this to false so that it will be turned off in in the website
                )

        )



)

i want to change the active so i could turn off pathgroups

我想改变活动,所以我可以关闭路径组

1 个解决方案

#1


0  

You need to make sure the url with PUT performs an UPDATE (it's a convention not an obligation). You need to know perfectly what your data looks like.

您需要确保具有PUT的URL执行更新(这是惯例而非义务)。您需要完全了解数据的外观。

And here what that should look like (with some explanation...)

这里看起来应该是什么样的(有一些解释......)

            // New values
            // This should contain all the values with the new value of the active key
            // it should start like this based on the output you provided
            // $data = array(
            //     'pathsGroups' => array(
            //           array(
            //              'condition' => ...
            //    ...etc
            // );
            $data = array(
                 // values
            );

            $wh = curl_init();

            curl_setopt($wh, CURLOPT_URL, "https://core.voluum.com/campaigns/" . $id);
            curl_setopt($wh, CURLOPT_RETURNTRANSFER, 1);
            // You use put exactly the same way as GET
            curl_setopt($wh, CURLOPT_CUSTOMREQUEST, "PUT");
            // Here you pass your new values, with GET we don't have this
            curl_setopt($wh, CURLOPT_POSTFIELDS, http_build_query($data));

            $head = array();
            $head[] = "Cwauth-Token: " . $tok;
            curl_setopt($wh, CURLOPT_HTTPHEADER, $head);

            $resulta = curl_exec($wh);

            if (curl_errno($wh)) {
                echo 'Error:' . curl_error($wh);
            }

            // Could help http://lornajane.net/posts/2009/putting-data-fields-with-php-curl

#1


0  

You need to make sure the url with PUT performs an UPDATE (it's a convention not an obligation). You need to know perfectly what your data looks like.

您需要确保具有PUT的URL执行更新(这是惯例而非义务)。您需要完全了解数据的外观。

And here what that should look like (with some explanation...)

这里看起来应该是什么样的(有一些解释......)

            // New values
            // This should contain all the values with the new value of the active key
            // it should start like this based on the output you provided
            // $data = array(
            //     'pathsGroups' => array(
            //           array(
            //              'condition' => ...
            //    ...etc
            // );
            $data = array(
                 // values
            );

            $wh = curl_init();

            curl_setopt($wh, CURLOPT_URL, "https://core.voluum.com/campaigns/" . $id);
            curl_setopt($wh, CURLOPT_RETURNTRANSFER, 1);
            // You use put exactly the same way as GET
            curl_setopt($wh, CURLOPT_CUSTOMREQUEST, "PUT");
            // Here you pass your new values, with GET we don't have this
            curl_setopt($wh, CURLOPT_POSTFIELDS, http_build_query($data));

            $head = array();
            $head[] = "Cwauth-Token: " . $tok;
            curl_setopt($wh, CURLOPT_HTTPHEADER, $head);

            $resulta = curl_exec($wh);

            if (curl_errno($wh)) {
                echo 'Error:' . curl_error($wh);
            }

            // Could help http://lornajane.net/posts/2009/putting-data-fields-with-php-curl