簡體   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