Can't send the request to the server

这一生的挚爱 提交于 2019-12-23 04:27:24

问题


I've some problem with the PHP script. So, I'm trying to connect to the FMI Server, but when I'm enter a valid credentials the server always return HTTP code 330, instead of 200 OK. Also when I'm trying with invalid credentials it's return 401 and it's okay, but why I've this problem only with VALID credentials? What I'm tried?

curl_setopt($ch,CURLOPT_ENCODING , "gzip");

But no luck :(

Here's my code:

<?php
$username = "callibra@yandex.ru"; //Valid login
$password = "callibra4App"; //Valid Password
class FMIWebApplication {
    private $client = array(
        "user-agent" => "FindMyiPhone/472.1 CFNetwork/711.1.12 Darwin/14.0.0",
        "headers" => array(
                "X-Apple-Realm-Support" => "1.0",
                "X-Apple-Find-API-Ver" => "3.0",
                "X-Apple-AuthScheme" => "UserIdGuest",
                "X-Apple-I-MD-RINFO" => "17106176",
                "Accept" => "*/*",
                "Connection" => "keep-alive",
                "Accept-Encoding" => "br, gzip, deflate",
                "Accept-Language" => "en-us",
                "X-Apple-I-TimeZone" => "GMT+2",
                "X-Apple-I-Locale" => "en_US"
                )
);
    public $username;
    public $password;
    public $devices = array();

    public function __construct($username, $password) {
        $this->username = $username;
        $this->password = $password;
        $this->authenticate();
    }

    public function authenticate() {
        $url = "https://fmipmobile.icloud.com/fmipservice/device/".$this->username."/initClient";
        list($headers, $body) = $this->curlPOST($url, "", $this->username.":".$this->password);
        /*
        if ($headers["http_code"] == 200) {
            return 200;
        };
        if ($headers["http_code"] == 401) {
            return 401;
        };
        if ($headers["http_code"] == 403) {
            return 403;
        };*/
        echo $headers["http_code"];
    }


    private function curlPOST($url, $body, $authentication = "") {
        $ch = curl_init($url);
        curl_setopt($ch, CURLOPT_CUSTOMREQUEST, "POST");
        curl_setopt($ch, CURLOPT_POSTFIELDS, $body);                                                              
        curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
        curl_setopt($ch, CURLOPT_VERBOSE, 1);
        curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
        curl_setopt($ch, CURLOPT_HEADER, 1);
        curl_setopt($ch, CURLOPT_USERAGENT, $this->client["user-agent"]);
        curl_setopt($ch, CURLOPT_SSLVERSION, 6);
        if (strlen($authentication) > 0) {
            curl_setopt($ch, CURLOPT_USERPWD, $authentication);  
        }
        $arrHeaders = array();
        $arrHeaders["Content-Length"] = strlen($request);
        foreach ($this->client["headers"] as $key=>$value) {
            array_push($arrHeaders, $key.": ".$value);
        }
        curl_setopt($ch, CURLOPT_HTTPHEADER, $arrHeaders);
        $response = curl_exec($ch);
        $info = curl_getinfo($ch);
        $header_size = curl_getinfo($ch, CURLINFO_HEADER_SIZE);
        $responseBody = substr($response, $header_size);
        $headers = array();
        foreach (explode("\r\n", substr($response, 0, $header_size)) as $i => $line) {
            if ($i === 0)
                $headers['http_code'] = $info["http_code"];
            else {
                list ($key, $value) = explode(': ', $line);
                if (strlen($key) > 0)
                    $headers[$key] = $value;
            }
        }
        return array($headers, json_decode($responseBody, true));
    }
}
$API = new FMIWebApplication($username, $password);
$API->authenticate();
?>

That's what I'm getting from the server:

HTTP/1.1 330 Server: AppleHttpServer/70a91026 Date: Thu, 07 Mar 2019 13:23:40 GMT Content-Length: 0 Connection: keep-alive X-Responding-Instance: fmipservice:34000504:mr23p40ic-ztdg08174101:7004:1903B41:738abffa X-Responding-Server: mr23p40ic-ztdg08174101_004 X-Responding-Partition: p40 X-Apple-MMe-Host: p40-fmipmobile.icloud.com X-Apple-MMe-Scope: 639524741 Strict-Transport-Security: max-age=31536000; includeSubDomains Set-Cookie: NSC_q40-gnjqtfswjdf=6ad0a3dee1e78d9bd168cb5a7ceafc289128c7a38269b4bddde70dac09e4e273e5f12331;path=/;secure;httponly via: icloudedge:mc10p01ic-zteu01141501:7401:18RC846:Manchester X-Apple-Request-UUID: 8d5dc207-f1f8-453f-8863-9e0d5ab3b58b access-control-expose-headers: X-Apple-Request-UUID access-control-expose-headers: Via 330

来源:https://stackoverflow.com/questions/55044450/cant-send-the-request-to-the-server

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!