【发布时间】:2019-06-13 10:53:12
【问题描述】:
这是在 wordpress 上。
如果 用户名、密码和参考都以字母开头,然后请求和响应工作正常。
但如果用户名、密码或参考是一个数字,那么它似乎不会发送。
在邮递员上它工作正常。
我试着把它当作一个变量
$data = "body xml"
CURLOPT_POSTFIELDS => $data,
这不起作用,但我也不确定如何在其中获得 $user 和 $pass。
$username = $current_user->first_name;
$password = $current_user->last_name;
$curl = curl_init();
curl_setopt_array($curl, array(
CURLOPT_PORT => "xxxxxxxxxxxx",
CURLOPT_URL => "xxxxxxxxxxxxxxxxx",
CURLOPT_RETURNTRANSFER => true,
CURLOPT_ENCODING => "",
CURLOPT_MAXREDIRS => 10,
CURLOPT_TIMEOUT => 30,
CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
CURLOPT_CUSTOMREQUEST => "POST",
CURLOPT_POSTFIELDS => "<root>\r\n <user>" .$username. "</user>\r\n <pass>" .$password. "</pass>\r\n <reference>12345</reference>\r\n</root>\r\n",
CURLOPT_HTTPHEADER => array(
"Accept: application/xml",
"Cache-Control: no-cache",
"Connection: keep-alive",
"Content-Type: application/xml",
"Host: xxxxxxxxxxxx",
"Postman-Token: xxxxxxxxxxxxxxxx",
"User-Agent: PostmanRuntime/7.13.0",
"accept-encoding: gzip, deflate",
"cache-control: no-cache",
"content-length: 107"
),
));
$response = curl_exec($curl);
$err = curl_error($curl);
curl_close($curl);
if ($err) {
echo "There are no orders to show on this account ";
} else {
结果显示在表格等中
所以如果用户名是 Bob,密码是 mypass,引用是 ABC123,那么它会正常工作
但是
如果用户名是 Sid,密码 1234 并引用 ABC444,那么这将不起作用
如果用户名是 Alice 密码 mypass22 并且引用 22 那么这将不起作用
似乎去掉了 This 中的数字
<root>\r\n <user>" .$username. "</user>\r\n <pass>" .$password. "</pass>\r\n <reference>12345</reference>\r\n</root>\r\n
我已经回显了 $username 和 $password 并且在页面上的回显中它们工作正常,所以我的猜测是,它是 Curl 中的 POSTFIELDS 剥离数字?或者只是不发送?
编辑
尝试改变
CURLOPT_POSTFIELDS => "<root>\r\n <user>" .$username. "</user>\r\n <pass>" .$password. "</pass>\r\n <reference>12345</reference>\r\n</root>\r\n",
到
$input_xml = '<root>
<user>sid</user>
<pass>Mypass</pass>
<reference>12345</reference>
</root>';
CURLOPT_POSTFIELDS => $input_xml,
但也没有用
【问题讨论】:
标签: wordpress curl numbers httprequest