2017-07-21 64 views
0

我正在嘗試通過PHP登錄到3cx AdminPanel。3CX通過PHP登錄

文章網址在那裏我有憑據傳遞是

noonecares.com:5001/api/login如果我通過瀏覽器的請求具有下列頭登入:

  • 接受:應用/ JSON,文本/無格式,/
  • 內容類型:應用/ JSON;字符集= UTF-8
  • 的Content-Length:#CONTENT_LENGTH#
  • 接受編碼:gzip,放氣,BR
  • 產地:https://noonecares.com:5001
  • 的Referer:https://noonecares.com/
  • X-3CX-版本:15.5.1694.0

內容*(請求有效載荷) *:{用戶名:「xxxxx」,密碼:「xxxxxx」}

在Php我也使用這個標頭

$opts = [ 
     "http" => [ 
      "method" => "POST", 
      "header" => 
       "Accept:application/json, text/plain, */*\n\r" . 
       "Accept-Encoding:gzip, deflate, br\n\r" . 
       "Content-Type:application/json;charset=UTF-8\n\r" . 
       "Origin:https://noonecares.com:5001\n\r" . 
       "Referer:https://noonecares.com:5001\n\r" . 
       "Content-Length:" . strlen($data) . "\n\r", 

      "content" => json_encode(["Username" => "xxxxx","Password" => "xxxxxx"]), 
     ] 
    ]; 

我嘗試用下面的代碼發送請求:

$result = file_get_contents("noonecares.com:5001/api/login", false, stream_context_create($opts)); 

但我總是得到「錯誤的請求」的響應和嘗試的couble後,我收到了超時周邊

問候最大

+0

我不知道這是否解決您的問題,但通常應該是'\ r \ N',而不是'\ n \ r'。 –

回答

0

也許你可以試試這個:

$opts = [ 
    "https" => [ 

,而不是

$opts = [ 
    "http" => [ 

你也可以試試這個

$result = file_get_contents("https://noonecares.com:5001/api/login", false, stream_context_create($opts));