を使用しているとき、私はAPIを呼び出して、次のPHPコードがあります。「無効なAPIリクエスト」CURL_EXEC
$forcetest = 1;
$url = "https://www.website.com/api/pointTotal.php?userId=" . $userId;
if ($forcetest || (isset($_SERVER['ON_TEST_SERVER']) && ($_SERVER['ON_TEST_SERVER']))){
$url = "https://wwwtest.website.com/api/pointTotal.php?userId=" . $userId;
}
$curl = curl_init();
curl_setopt_array($curl, array(
CURLOPT_RETURNTRANSFER => 1,
CURLOPT_URL => $url
));
curl_setopt($curl, CURLOPT_HTTPHEADER, array(
'sharedSecret: abc123',
));
//curl_setopt($curl, CURLOPT_FOLLOWLOCATION, true); //tested to see if this would work, didn't seem to matter
// Only do this if on dev/test
if ($forcetest || (isset($_SERVER['ON_TEST_SERVER']) && ($_SERVER['ON_TEST_SERVER']))) {
curl_setopt($curl, CURLOPT_SSL_VERIFYHOST, false);
curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, false);
}
$response = curl_exec($curl);
print($response);
if(!$response){
die('Error: "' . curl_error($curl) . '" - Code: ' . curl_errno($curl));
}
を生産(すなわち$forcetest = 0;
)に行くとき、私の問題は、それがPROD APIを呼び出して、うまく動作し、 prodデータベースを使用します。私はそれを切り替え、それはテストのAPIを呼び出すためにwwwtestサブドメインに行き、私はエラーが {"success":false,"errors":["Invalid API request"]}
「無効なAPI要求を」返さ取得する場合、APIのコードではものではありませんので、そのように私には思えます何かcurl_execがやっている/間違っているが、私は何を理解することはできません。私がapiに直接行くと、彼らは両方とも私のブラウザで正しい情報を返すので、私はそれがうまく動作していることを知っています。おそらく証明書の問題か、そのサブドメイン/サーバーに何らかの種類のxssを設定するとエラーになるのでしょうか?私は一種の損失です。
ありがとうございます。
編集:CLI curlコマンドとヘッダ出力:
[[email protected]] $ curl -H 'sharedSecret: abc123' 'https://wwwtest.website.com/api/pointTotal.php?userId=1472&rewardsType=f' -vvv
* About to connect() to wwwtest.website.com port 443
* Trying xxx.xx.xx.xx... connected
* Connected to wwwtest.website.com (xxx.xx.xx.xx) port 443
* successfully set certificate verify locations:
* CAfile: /etc/pki/tls/certs/ca-bundle.crt
CApath: none
* SSLv2, Client hello (1):
SSLv3, TLS handshake, Server hello (2):
SSLv3, TLS handshake, CERT (11):
SSLv3, TLS handshake, Server finished (14):
SSLv3, TLS handshake, Client key exchange (16):
SSLv3, TLS change cipher, Client hello (1):
SSLv3, TLS handshake, Finished (20):
SSLv3, TLS change cipher, Client hello (1):
SSLv3, TLS handshake, Finished (20):
SSL connection using RC4-SHA
* Server certificate:
* subject: /C=US/ST=New Mexico/L=Albuquerque/O=removed/CN=*.website.com
* start date: 2013-07-29 00:00:00 GMT
* expire date: 2016-10-05 12:00:00 GMT
* subjectAltName: wwwtest.website.com matched
* issuer: /C=US/O=DigiCert Inc/CN=DigiCert Secure Server CA
* SSL certificate verify ok.
> GET /api/pointTotal.php?userId=1472&rewardsType=f HTTP/1.1
> User-Agent: curl/7.15.5 (x86_64-redhat-linux-gnu) libcurl/7.15.5 OpenSSL/0.9.8b zlib/1.2.3 libidn/0.6.5
> Host: wwwtest.website.com
> Accept: */*
> sharedSecret: abc123
>
< HTTP/1.1 200 OK
< Date: Wed, 29 Jun 2016 18:27:25 GMT
< Server: Apache/2.2.3 (CentOS) DAV/2 mod_ssl/2.2.3 OpenSSL/0.9.8e-fips-rhel5
< Access-Control-Request-Headers: accept, auth-key
< Access-Control-Allow-Origin: https://customeraccess.website.com
< Access-Control-Allow-Headers: sharedSecret
< Content-Length: 36
< Content-Type: text/html
Connection #0 to host wwwtest.website.com left intact
* Closing connection #0
* SSLv3, TLS alert, Client hello (1):
{"userId":"1472","pointTotal":50600}
も電話をかけるPHPコードにこれを追加
curl_getinfo($curl, CURLINFO_HEADER_OUT)
、それが問題のようです何である404
を出力しますが、 urlに行くと、immediatleyが正しい結果を返すので、何が原因で起こっているのか分かりません。
wwwtest.website.com/api/epson/pointTotal.phpエンドポイントが本当に到達可能なのですか?解決策として、最初の点が助けにならない場合は、CLIフォームに変換してデバッグすることをお勧めします。 -vvvをもっと冗長に使う – Rinat
@Rinat 'CURLINFO_HTTP_CODE'をチェックしたところ、404に達していましたが、私は' CURLINFO_EFFECTIVE_URL'を出力した理由が分かりません。ブラウザからアクセスできるようです。無効なコール応答を説明します。なぜそれがそれを得ているのか分からない。私はCLIのフォームであなたが何を意味するか分からない。 – Josh
私はcurl -H 'sharedSecret:abc123' 'あなたのurl' -vvvを書いて、 – Rinat