无法将POST请求发送到远程服务器

时间:2019-03-07 16:42:25

标签: php http curl icloud

我的PHP脚本有问题。因此,我试图连接到FMI服务器,但是当我输入有效的凭据时,服务器始终返回HTTP代码330,而不是200 OK。另外,当我尝试使用无效的凭据时,它会返回401并且可以,但是为什么我只有有效的凭据才有这个问题?我尝试过什么?

[http_code] => 330
    [Server] => AppleHttpServer/70a91026
    [Date] => Thu, 07 Mar 2019 16:28:43 GMT
    [Content-Length] => 0
    [Connection] => keep-alive
    [X-Responding-Instance] => fmipservice:34000304:mr23p40ic-ztdg08174201:8004:1903B41:738abffa
    [X-Responding-Server] => mr23p40ic-ztdg08174201_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=28d4a3da3b8d7d4a29e88efdb77458dc452141c242c6b34f851963d19b2a802f8285306d;path=/;secure;httponly
    [via] => icloudedge:mc10p00ic-zteu01142001:7401:18RC846:Manchester
    [X-Apple-Request-UUID] => d699f9cd-7956-47ab-b181-66c2e396182c
    [access-control-expose-headers] => Via

但没有运气:(

来自删除服务器的响应:

<?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();
?>

这是我的代码:

{{1}}

P.S。 cURL输出为空:(

0 个答案:

没有答案