[英]Getting empty response from php curl
Getting empty message as response PHP CURL 获取空消息作为响应PHP CURL
I have tried print_r, the httpcode is 200, even CURLOPT_VERBOSE shows no error. 我试过print_r,httpcode是200,甚至CURLOPT_VERBOSE都没有显示错误。 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? 有没有php大师关心帮忙?
Content-Length: 0
means your content's length is zero. Content-Length: 0
表示您的内容长度为零。
Actually it is a good practice to return no content on POST request. 实际上,在POST请求中不返回任何内容是一个好习惯。 So your curl code probably works fine. 所以你的卷曲代码可能工作正常。
The idea of this response is just to set you a session cookie. 此响应的想法只是为您设置会话cookie。 Using this cookie you can send other requests being already authorized. 使用此cookie,您可以发送已经授权的其他请求。
我找到了答案,有效载荷必须是json_encode() - ed。这是我的坏事
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.