> ## Documentation Index
> Fetch the complete documentation index at: https://devdocs.xbox.com/llms.txt
> Use this file to discover all available pages before exploring further.

# HTTP 構成

> PFSetHttpRetrySettings と関連 API を使用して、PlayFab Services C SDK の HTTP 再試行、タイムアウト、およびレスポンス圧縮設定を構成します。

PlayFab Services SDK は、自動再試行の動作やレスポンス圧縮を含め、HTTP リクエストの実行方法を構成する関数を提供します。これらの設定はグローバルであり、SDK によって行われるすべての PlayFab API 呼び出しに適用されます。

HTTP 設定は、[**PFInitialize**](/services/playfab/api-references/c/pfcore/functions/pfinitialize) と [**PFServicesInitialize**](/services/playfab/api-references/c/pfservices/functions/pfservicesinitialize) を呼び出した後、API 呼び出しを行う前に構成してください。

## 再試行設定

**PFHttpRetrySettings** 構造体は、スロットリングエラー (HTTP 429) などの一時的な HTTP 失敗を SDK がどのように処理するかを制御します。デフォルトでは、SDK はこれらの失敗をバックオフ付きで自動的に再試行します。

| フィールド                        | 型          | デフォルト  | 説明                                                       |
| ---------------------------- | ---------- | ------ | -------------------------------------------------------- |
| `allowRetry`                 | `bool`     | `true` | SDK が特定のエラーを自動的に再試行するかどうかを制御します。一部のエラーは再試行されず、常に直接返されます。 |
| `minimumRetryDelayInSeconds` | `uint32_t` | 2      | 失敗したリクエストを再試行するまで待機する最小秒数。2 秒未満に設定することはできません。            |
| `timeoutWindowInSeconds`     | `uint32_t` | 20     | SDK がエラーを呼び出し元に返す前に再試行を試みる最大秒数。                          |

SDK が自動的に再試行するエラーの詳細については、[PlayFab エラーの処理](/services/playfab/sdks/c/errors)を参照してください。

### 再試行設定の設定

再試行動作をカスタマイズするには **PFSetHttpRetrySettings** を呼び出します。たとえば、長い待機を許容できる呼び出しの再試行ウィンドウを増やすには:

```cpp theme={null}
PFHttpRetrySettings retrySettings{};
retrySettings.allowRetry = true;
retrySettings.minimumRetryDelayInSeconds = 4;
retrySettings.timeoutWindowInSeconds = 60;

HRESULT hr = PFSetHttpRetrySettings(&retrySettings);
if (FAILED(hr))
{
    // Handle error
}
```

### 再試行設定の取得

現在の再試行構成を取得するには **PFGetHttpRetrySettings** を呼び出します:

```cpp theme={null}
PFHttpRetrySettings currentSettings{};
HRESULT hr = PFGetHttpRetrySettings(&currentSettings);
if (SUCCEEDED(hr))
{
    printf("Retry enabled: %s\n", currentSettings.allowRetry ? "true" : "false");
    printf("Min delay: %u seconds\n", currentSettings.minimumRetryDelayInSeconds);
    printf("Timeout window: %u seconds\n", currentSettings.timeoutWindowInSeconds);
}
```

### 自動再試行の無効化

すべての再試行ロジックを自分で処理したい場合は、自動再試行を無効にします:

```cpp theme={null}
PFHttpRetrySettings retrySettings{};
retrySettings.allowRetry = false;
retrySettings.minimumRetryDelayInSeconds = 2;
retrySettings.timeoutWindowInSeconds = 20;

HRESULT hr = PFSetHttpRetrySettings(&retrySettings);
```

## HTTP 設定

**PFHttpSettings** 構造体は、すべての SDK リクエストの一般的な HTTP 動作を制御します。

| フィールド                        | 型      | デフォルト   | 説明                                                                                                 |
| ---------------------------- | ------ | ------- | -------------------------------------------------------------------------------------------------- |
| `requestResponseCompression` | `bool` | `false` | 有効になると、SDK は `Accept-Encoding` ヘッダーを `application/gzip` に設定することにより、API レスポンスを gzip 圧縮するようリクエストします。 |

### レスポンス圧縮の有効化

レスポンス圧縮を有効にすると帯域幅の使用量を削減でき、大きなペイロードを返す呼び出しに役立ちます。有効にするには **PFSetHttpSettings** を呼び出します:

```cpp theme={null}
PFHttpSettings httpSettings{};
httpSettings.requestResponseCompression = true;

HRESULT hr = PFSetHttpSettings(&httpSettings);
if (FAILED(hr))
{
    // Handle error
}
```

<Note>
  圧縮されたレスポンスを解凍するには、**HCHttpCallPerformAsync** を呼び出す前に **HCHttpCallResponseSetGzipCompressed** を呼び出す必要があります。
</Note>

### HTTP 設定の取得

現在の HTTP 構成を取得するには **PFGetHttpSettings** を呼び出します:

```cpp theme={null}
PFHttpSettings currentSettings{};
HRESULT hr = PFGetHttpSettings(&currentSettings);
if (SUCCEEDED(hr))
{
    printf("Response compression: %s\n", currentSettings.requestResponseCompression ? "enabled" : "disabled");
}
```

## 典型的な初期化パターン

次の例は、HTTP 構成が全体的な SDK 初期化フローのどこに位置するかを示しています:

```cpp theme={null}
// 1. Initialize the SDK
HRESULT hr = PFInitialize(nullptr);
hr = PFServicesInitialize(nullptr);

// 2. Configure HTTP settings before making any API calls
PFHttpRetrySettings retrySettings{};
retrySettings.allowRetry = true;
retrySettings.minimumRetryDelayInSeconds = 2;
retrySettings.timeoutWindowInSeconds = 30;
PFSetHttpRetrySettings(&retrySettings);

PFHttpSettings httpSettings{};
httpSettings.requestResponseCompression = true;
PFSetHttpSettings(&httpSettings);

// 3. Create service config and begin making API calls
// ...
```


## Related topics

- [構成](/ja-jp/services/xbox-services/player-data/stats-leaderboards/featured-stats/config/index.md)
- [HCHttpDisableAssertsForSSLValidationInDevSandboxes](/ja-jp/reference/live/httpclient/httpclient/functions/hchttpdisableassertsforsslvalidationindevsandboxes.md)
- [Content Test Application (CTA) ストリーム構成の概要](/ja-jp/build/core-features/common/game-streaming/game-streaming-content-test-application-stream-config.md)
- [HCConfigSetting](/ja-jp/reference/live/httpclient/httpclient/enums/hcconfigsetting.md)
- [エラーコード](/ja-jp/reference/errorcodes.md)
