如何在curl php中传递url值
$description = "some test data and url";
$description .="http://www.mydata.com?test=1&user=4&destination=645&source=stackoverflow";
curl_setopt($sch, CURLOPT_URL, "myserverurl");
curl_setopt($sch, CURLOPT_HEADER, 0);
curl_setopt($sch, CURLOPT_POST, true);
curl_setopt($sch, CURLOPT_RETURNTRANSFER , 1);
curl_setopt($sch, CURLOPT_POSTFIELDS, "orgid=$orgid&description=$description&external=1");
curl_setopt ($sch, CURLOPT_SSL_VERIFYHOST, 0);
curl_setopt ($sch, CURLOPT_SSL_VERIFYPEER, 0);
当我检查服务器(myserverurl)时。
我可以看到描述字段,例如
“一些测试数据和网址 http://www.mydata.com?test =1”。
我丢失了“&”之后的描述
是的,我们可以在使用curl发送之前对url进行编码,但我无权在第三方api服务器上再次解码url
$description = "some test data and url";
$description .="http://www.mydata.com?test=1&user=4&destination=645&source=stackoverflow";
curl_setopt($sch, CURLOPT_URL, "myserverurl");
curl_setopt($sch, CURLOPT_HEADER, 0);
curl_setopt($sch, CURLOPT_POST, true);
curl_setopt($sch, CURLOPT_RETURNTRANSFER , 1);
curl_setopt($sch, CURLOPT_POSTFIELDS, "orgid=$orgid&description=$description&external=1");
curl_setopt ($sch, CURLOPT_SSL_VERIFYHOST, 0);
curl_setopt ($sch, CURLOPT_SSL_VERIFYPEER, 0);
when i check on the server (myserverurl).
I can see the description field like
"some test data and url http://www.mydata.com?test=1".
i lost the description after '&'
yes , we can encode the url before sending with curl, but i do not have access to decode the url again on that third party api server
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
如果您
urlencode
每个参数的值会怎么样?正在发送?您不必担心另一端的解码:这是通过 GET / POST 发送数据的标准方式
:
如果这不起作用,请尝试使用
rawurlencode
? (如果我没记错的话,空格是有区别的)What if you
urlencode
the value of each parameter you are sending ?You don't have to worry about decoding on the other side : it is standard way of sending data through GET / POST
Something like :
And if this doesn't work, try with
rawurlencode
? (there is a difference for spaces, if I remember correctly)简单的。 输入后即可获取当前 URL。
因此,如果您输入
(我假设
mydata.com
是您的服务器),您可以非常轻松地回显它:并且上面的回显应该给出:
从那时起,您可以简单地将整个字符串保存到数据库,或通过 $_SERVER['test'] 保存各个变量(测试、用户、目标、源),或者,如果其中一些变量不同,您可以通过
分解它们&
字符来动态保存它们。Easy. You can simply get the current URL after it has been entered.
So if you enter
(I assume, that
mydata.com
is your server), you can echo it very easily:And the above echo should give:
From then, you can simply either save the entire string to the database, or save individual variables (test, user, destination, source) by
either $_SERVER['test']
, or, if a number of them varies, you can explode them by&
character to save them dynamically.将发布的数据放入一个数组中,并使用该数组作为您的
CURLOPT_POSTFIELDS
。您可以在
$_POST['description']
中获取描述。示例
test.php
testcurl.php
结果
Put the data for post in an array and use that array as your
CURLOPT_POSTFIELDS
.You can get the description in
$_POST['description']
.Example
test.php
testcurl.php
result
这是简单的解决方案。 如果您正在使用 PHP 函数curl_escape()`
This is the easy solution. If you are working on php use function curl_escape()`