0

問題

実稼働サーバーで、私のコード (以下を参照) が予期しない401 error. ただし、私の開発サーバーでは問題なく動作します。予期しない401 error. 私のコードは開発サーバーで正常に動作するため、コードPHPがエラーを引き起こしているとは思いません。

アドバイスやガイダンスをいただければ幸いです。


コード

$ch = curl_init();
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, false);
curl_setopt($ch, CURLOPT_MAXREDIRS, 10);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_TIMEOUT, 60);
curl_setopt($ch, CURLOPT_HTTPAUTH, CURLAUTH_DIGEST); 
curl_setopt($ch, CURLOPT_USERPWD, $VAR:$VAR2);
curl_setopt($ch, CURLOPT_HTTPHEADER, array('Content-type: application/json'));
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, false);
curl_setopt($ch, CURLOPT_HEADER, true);
curl_setopt($ch, CURLOPT_USERAGENT, "|MY API V1.0|");
curl_setopt($ch, CURLOPT_HTTPHEADER, array('Content-type: application/json','Content-Length: ' . strlen($POST)));
curl_setopt($ch, CURLOPT_CUSTOMREQUEST, "POST");
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_POSTFIELDS, $POST);

これらはcurl_info、本番サーバーと開発サーバーの両方の応答です。

生産 (パフォーマンスが遅い)

カール情報

Array ( 
  [url] => https://example.com/v0.1.0/token/create-token.hcw
  [content_type] => text/html; charset=utf-8 
  [http_code] => 200
  [header_size] => 685 
  [request_size] => 766 
  [filetime] => -1
  [ssl_verify_result] => 18 
  [redirect_count] => 1 
  [total_time] => 20.13144 
  [namelookup_time] => 0.000381 
  [connect_time] => 0.000473 
  [pretransfer_time] => 0.010784 
  [size_upload] => 0 
  [size_download] => 80 
  [speed_download] => 3 
  [speed_upload] => 0 
  [download_content_length] => 80 
  [upload_content_length] => 0 
  [starttransfer_time] => 0.067625 
  [redirect_time] => 20.063809 
) 

最初の応答 (401)

HTTP/1.0 401 Unauthorized 
Date: Mon, 04 May 2015 02:19:46 GMT 
Server: Apache 
WWW-Authenticate: Digest realm="MY API",qop="auth",nonce="5546d75645e7d",opaque="5c4c3e3231714690a63d174
a9cf26780" 
Cache-Control: max-age=0 
Expires: Mon, 04 May 2015 02:19:46
GMT X-Powered-By: PleskLin 
X-UA-Compatible: IE=Edge,chrome=1
Content-Length: 111 
Connection: close 
Content-Type: text/html; charset=utf-8

2 番目の応答 (200 - 20 秒以上の遅延後)

HTTP/1.1 200 OK 
Date: Mon, 04 May 2015 02:20:06 GMT
Server: Apache 
Cache-Control: max-age=0 
Expires: Mon, 04 May 2015 02:20:06 GMT 
X-Powered-By: PleskLin 
X-UA-Compatible: IE=Edge,chrome=1
Content-Length: 80 
Connection: close 
Content-Type: text/html; charset=utf-8

JSON 文字列:

{"response":"success", "content":[{"token":"ko67atw1CFRSEdllOyeklRIMPb1ZS0a0"}]}

開発 (良好なパフォーマンス)

カール情報

Array ( 
  [url] => http://localhost/mydomain/v0.1.0/token/create-token.hcw
  [content_type] => text/html; charset=utf-8 
  [http_code] => 200 
  [header_size] => 736 
  [request_size] => 348 
  [filetime] => -1 
  [ssl_verify_result] => 0
  [redirect_count] => 1 
  [total_time] => 0.005946 
  [namelookup_time] => 8.0E-5 
  [connect_time] => 8.3E-5 
  [pretransfer_time] => 0.000133 
  [size_upload] => 20 
  [size_download] => 0 
  [speed_download] => 0
  [speed_upload] => 3363 
  [download_content_length] => 0
  [upload_content_length] => 20 
  [starttransfer_time] => 0.002765
  [redirect_time] => 0.003146
) 

最初の応答 (200)

HTTP/1.1 200 OK 
Date: Mon, 04 May 2015 02:33:40 GMT 
Server: Apache/2.2.14 (Unix) DAV/2 mod_ssl/2.2.14 OpenSSL/0.9.8l PHP/5.3.1 mod_perl/2.0.4 Perl/v5.10.1 
X-Powered-By: PHP/5.3.1 
Cache-Control: max-age=0 
Expires: Mon, 04 May 2015 02:33:40 GMT 
X-UA-Compatible: IE=Edge,chrome=1 
Vary: Accept-Encoding
Content-Length: 0 
Content-Type: text/html; charset=utf-8 

セカンドレスポンス (200)

HTTP/1.1 200 OK 
Date: Mon, 04 May 2015 02:33:40 GMT 
Server: Apache/2.2.14 (Unix) DAV/2 mod_ssl/2.2.14 OpenSSL/0.9.8l PHP/5.3.1 mod_perl/2.0.4 Perl/v5.10.1 
X-Powered-By: PHP/5.3.1 
Cache-Control: max-age=0 
Expires: Mon, 04 May 2015 02:33:40 GMT 
X-UA-Compatible: IE=Edge,chrome=1 
Vary: Accept-Encoding 
Content-Length: 0 
Content-Type: text/html; charset=utf-8

JSON 文字列:

{"response":"success", "content":[{"token":"ko67atw1CFRSEdllOyeklRIMPb1ZS0a0"}]}
4

1 に答える 1

0
curl_setopt($ch, CURLOPT_HTTPHEADER, array('Content-type: application/json'));

犯人でした。何日も経った後、現在は修正されています。

于 2015-05-05T04:18:24.160 に答える