1
$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

4

4 回答 4

1

如果您发送的每个参数urlencode值怎么办?

您不必担心另一端的解码:这是通过 GET / POST 发送数据的标准方式

就像是 :

curl_setopt($sch, CURLOPT_POSTFIELDS, 
    "orgid=" . urlencode($orgid) 
    . "&description=" . urlencode($description) 
    . "&external=1"
);

如果这不起作用,请尝试使用rawurlencode? (如果我没记错的话,空格会有所不同)

于 2009-07-22T06:47:14.570 回答
0

简单的。输入后,您可以简单地获取当前 URL。

所以如果你输入

http://www.mydata.com?test=1&user=4&destination=645&source=stackoverflow

(我假设那mydata.com是你的服务器),你可以很容易地回显它:

$url = str_replace("?","",$_SERVER['REQUEST_URI']);
echo $url;

上面的回声应该给出:

test=1&user=4&destination=645&source=stackoverflow

从那时起,您可以简单地将整个字符串保存到数据库,或者保存单个变量(测试、用户、目标、源)either $_SERVER['test'],或者,如果它们的数量不同,您可以按&字符分解它们以动态保存它们。

于 2012-04-23T10:01:52.807 回答
0

将 post 的数据放入一个数组中,并将该数组用作您的CURLOPT_POSTFIELDS. 您可以在 中获取说明$_POST['description']

示例
test.php

<?php
$sch = curl_init(); 
$post_data=array();
$orgid='testorg';
$description = "some test data and url";
$description .="http://www.mydata.com?test=1&user=4&destination=645&source=stackoverflow";
$post_data['description']=$description;
$post_data['orgid']=$orgid;
$post_data['external']=1;
curl_setopt($sch, CURLOPT_URL, "localhost/testcurl.php");
curl_setopt($sch, CURLOPT_HEADER, 0);             
curl_setopt($sch, CURLOPT_POST, true);
curl_setopt($sch, CURLOPT_RETURNTRANSFER , 1);
curl_setopt($sch, CURLOPT_POSTFIELDS, $post_data);
$re=curl_exec($sch);

echo('<pre>');
echo($re);

测试卷曲.php

<?php
var_dump($_POST);

结果

array(3) {
  ["description"]=>
  string(94) "some test data and urlhttp://www.mydata.com?test=1&user=4&destination=645&source=stackoverflow"
  ["orgid"]=>
  string(7) "testorg"
  ["external"]=>
  string(1) "1"
}
于 2017-09-12T02:01:47.663 回答
0

这是简单的解决方案。如果你正在使用 php 函数 curl_escape()`

$msg=$_POST['Message'];

$ch = curl_init();
$new = curl_escape($ch, $msg);


$ch = curl_init("url".$new."/xyz.com");
$fp = fopen("example_homepage.txt", "w");

curl_setopt($ch, CURLOPT_FILE, $fp);
curl_setopt($ch, CURLOPT_HEADER, 0);

curl_exec($ch);
curl_close($ch);
fclose($fp);
于 2018-02-23T11:18:56.673 回答