繁体   English   中英

从php curl获取空响应

[英]Getting empty response from php curl

获取空消息作为响应PHP CURL

我试过print_r,httpcode是200,甚至CURLOPT_VERBOSE都没有显示错误。 但是,它没有返回任何值。

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;
}

我正进入(状态

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

有没有php大师关心帮忙?

Content-Length: 0表示您的内容长度为零。

实际上,在POST请求中不返回任何内容是一个好习惯。 所以你的卷曲代码可能工作正常。

此响应的想法只是为您设置会话cookie。 使用此cookie,您可以发送已经授权的其他请求。

我找到了答案,有效载荷必须是json_encode() - ed。这是我的坏事

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM