CURL中的数据urlencode是什么意思? [英] What means data-urlencode in CURL?

查看:452
本文介绍了CURL中的数据urlencode是什么意思?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已经花了很多时间试图找出php curl中的--data-urlencode是什么。

I have searched many hours trying to figure out what --data-urlencode is in php curl.

我尝试了这个,但是我不认为这是正确的。 / p>

I tried this, but I dont think its right.

$xmlpost .= "object1[file]=@https://www.lob.com/goblue.pdf";

在文档中是:

--data-urlencode "object1[file]=https://xxx.pdf" \

但是CURL是什么?
curl_setopt($ cpt,CURLOPT _ ??)

But what is it in CURL? curl_setopt($cpt, CURLOPT_??)

完整的API DOCS说我需要调用此函数

Full API DOCS says i need to call this

curl https://api.lob.com/v1/jobs \
-u test_0dc8d51e0acffcb1880e0f19c79b2f5b0cc: \
-d "name=Demo Quick Print Job" \
-d "to[name]=Harry Zhang" \
-d "to[address_line1]=123 Test Street" \
-d "to[address_city]=Mountain View" \
-d "to[address_state]=CA" \
-d "to[address_zip]=94085" \
-d "to[address_country]=US" \
-d "from[name]=Leore Avidar" \
-d "from[address_line1]=123 Test Street." \
-d "from[address_line2]=Apt 155" \
-d "from[address_city]=Sunnyvale" \
-d "from[address_state]=CA" \
-d "from[address_zip]=94085" \
-d "from[address_country]=US" \
-d "object1[name]=testobject" \
--data-urlencode "object1[file]=https://www.lob.com/goblue.pdf" \
-d "object1[setting_id]=100"

我正在尝试:

<?php
 $xmlpost = array(
    "name" => "PostalAddressConfirmation",
    "to" => array(
        "name" => "Testing",
        "address_line1" => "testvej",
        "address_city" => "test",
        "address_state" => "test",
        "address_zip" => "5000",
        "address_country" => "DK"
    ),
    "from" => array(
        "name" => "test ApS",
        "address_line1" => "testvej 25",
        "address_city" => "test",
        "address_state" => "test",
        "address_zip" => "5000",
        "address_country" => "DK"
    ),
    "object1" => array(
        "name" => "test Object",
        "setting_id" => "100",
        "file" => "https://lob.com/goblue.pdf"
    )
);

$cpt = curl_init("https://api.lob.com/v1/job");
curl_setopt_array($cpt, array(
    CURLOPT_RETURNTRANSFER => 1,
    CURLOPT_POSTFIELDS => $xmlpost,
    CURLOPT_USERPWD => 'test_0dc8d51e0acffcb1880e0f19c79b2f5b0cc:',
));

$result = curl_exec($cpt);


推荐答案

答案是,您甚至不需要考虑一下;请考虑以下代码:

The answer is that you don't even need to think about it; consider the following code:

$xmlpost  = [
    "name" => "PostalAddressConfirmation",

    // Lav modtager
    "to" => [
        "name" => "Jespern",
        "address_line1" => "hejvej",
        "address_city" => "Odense",
        "address_state" => "Syddanmark",
        // etc ...
    ],

    // Lav afsender
    "from" => [
        "name" => "test",
        // etc.
    ],

    //Dokument der skal sendes
    "object1" => [
        "name" => "AddressConfirmation",
        "setting_id" => 100,
        "file" => "https://www.lob.com/goblue.pdf",
        "quantity" => 1,
    ],
];

$cpt = curl_init("https://api.lob.com/v1/job");
curl_setopt_array($cpt, [
    CURLOPT_RETURNTRANSFER => 1,
    CURLOPT_USERPWD => 'test_0dc8d51e0acffcb1880e0f19c79b2f5b0cc:',
    CURLOPT_POSTFIELDS => http_build_query($xmlpost),
]);

$result = curl_exec($cpt);

http_build_query() 函数将构建要发布的适当字符串。

The http_build_query() function will build the appropriate string to post.

这篇关于CURL中的数据urlencode是什么意思?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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