Getting empty message as response PHP CURL
I have tried print_r, the httpcode is 200, even CURLOPT_VERBOSE shows no error. However, it is not returning any value.
curl = curl_init();
curl_setopt_array($curl, array(
CURLOPT_URL => "http://dummy.com/xxx",
CURLOPT_RETURNTRANSFER => true,
CURLOPT_VERBOSE=>true,
CURLOPT_TIMEOUT => 50,
CURLOPT_FOLLOWLOCATION => true,
CURLOPT_CUSTOMREQUEST => "POST",
CURLOPT_POSTFIELDS => $payload,
CURLOPT_HTTPHEADER => array(
"Authorization: Basic xxx",
),
));
$response = curl_exec($curl);
$err = curl_error($curl);
curl_close($curl);
if ($err) {
echo "error:" . $err;
} else {
echo "response: ".$response;
}
I am getting
response:
when I do CURLOPT_VERBOSE, this returned:
* Trying xxx.xx.xx.xxx...
* TCP_NODELAY set
* Connected to xxx.xx.xx.xxx (xxx.xx.xx.xxx) port xxxx (#0)
> POST /jw/web/json/plugin/org.joget.webservices.JsonRegistrationApiService/service HTTP/1.1
Host: xxx.xx.xxx.xxx
Accept: */*
Authorization: Basic Yxxxxxx
Content-Length: 775
Expect: 100-continue
Content-Type: application/json; boundary=------------------------916024cad4258a00
< HTTP/1.1 100
< HTTP/1.1 200
< Set-Cookie: JSESSIONID=4ED88EE9FD9746ED9C5F345F713FDB69; Path=/jw; HttpOnly
< X-Content-Type-Options: nosniff
< Content-Type: application/json;charset=utf-8
< Content-Length: 0
< Date: Tue, 16 Apr 2019 06:19:00 GMT
<
* Connection #0 to host xx.xx.xx.xxx left intact
Any php master care to help?
Content-Length: 0
means your content's length is zero.
Actually it is a good practice to return no content on POST request. So your curl code probably works fine.
The idea of this response is just to set you a session cookie. Using this cookie you can send other requests being already authorized.
我找到了答案,有效载荷必须是json_encode() - ed。这是我的坏事
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.