> ## 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.

# XUserGetTokenAndSignatureHttpHeader

> XUserGetTokenAndSignatureHttpHeader

# XUserGetTokenAndSignatureHttpHeader

指定 Web 要求的 HTTP 標頭。

## 語法

```cpp theme={null}
typedef struct XUserGetTokenAndSignatureHttpHeader {  
    const char* name;  
    const char* value;  
} XUserGetTokenAndSignatureHttpHeader  
```

### 成員

*name*\
類型：const char\*

標頭名稱。

*value*\
類型：const char\*

標頭值。

## 備註

若要以非同步方式擷取 Web 要求的 xtoken 和簽章，請呼叫 [XUserGetTokenAndSignatureAsync](/zh-TW/reference/system/xuser/functions/xusergettokenandsignatureasync) 函式。
此函式會接受 XUserGetTokenAndSignatureHttpHeader 結構的指標作為引數。

若要擷取 [XUserGetTokenAndSignatureAsync](/zh-TW/reference/system/xuser/functions/xusergettokenandsignatureasync) 呼叫的結果，請呼叫 [XUserGetTokenAndSignatureResult](/zh-TW/reference/system/xuser/functions/xusergettokenandsignatureresult) 函式。

下列範例示範如何以非同步方式擷取使用者的權杖和簽章。

```cpp theme={null}
HRESULT RequestTokenComplete(XAsyncBlock* abResult)
{
    size_t bufferSize;
    RETURN_IF_FAILED(XUserGetTokenAndSignatureResultSize(abResult, &bufferSize));

    std::vector<uint8_t> buffer(bufferSize);
    XUserGetTokenAndSignatureData* data;
    if (SUCCEEDED_LOG(XUserGetTokenAndSignatureResult(abResult, buffer.size(), buffer.data(), &data, nullptr /*bufferUsed*/)))
    {
        appLog.AddLog("Token: %s\n", data->token);
        if (data->signature != nullptr)
        {    
            appLog.AddLog("Signature: %s\n", data->signature);
        }
    }

    return S_OK;
}

HRESULT RequestTokenAsync(
    XTaskQueueHandle queue,
    const char* url,
    bool forceRefresh)
{
    auto asyncBlock = std::make_unique<XAsyncBlock>();
    ZeroMemory(asyncBlock.get(), sizeof(*asyncBlock));
    asyncBlock->queue = queue;
    asyncBlock->context = this;
    asyncBlock->callback = [](XAsyncBlock* ab)
    {
        LOG_IF_FAILED(static_cast<User*>(ab->context)->RequestTokenComplete(ab));
        delete ab;
    };


    XUserGetTokenAndSignatureOptions options = XUserGetTokenAndSignatureOptions::None;

    if (forceRefresh)
    {
        WI_SET_FLAG(options, XUserGetTokenAndSignatureOptions::ForceRefresh);
    }

    static const XUserGetTokenAndSignatureHttpHeader headers[] =
    {
        { "Accept", "application/json"},
        { "Why", "Because"},
    };

    if (SUCCEEDED_LOG(XUserGetTokenAndSignatureAsync(
        _handle.get(),
        options,
        "GET",
        url,
        ARRAYSIZE(headers),
        headers,
        0,
        nullptr,
        asyncBlock.get())))
    {
        // The call succeeded, so release the std::unique_ptr ownership of XAsyncBlock* since the callback will take over ownership.
        // If the call fails, the std::unique_ptr will keep ownership and delete the XAsyncBlock*
        asyncBlock.release();
    }

    return S_OK;
}
```

## 需求

**標頭：** XUser.h

**支援的平台：** Windows、XBOX One 系列主機和 XBOX Series 主機

## 另請參閱

[XUser](/zh-TW/reference/system/xuser/xuser_members)

[XUserGetTokenAndSignatureAsync](/zh-TW/reference/system/xuser/functions/xusergettokenandsignatureasync)

[XUserGetTokenAndSignatureResult](/zh-TW/reference/system/xuser/functions/xusergettokenandsignatureresult)


## Related topics

- [XUserGetTokenAndSignatureHttpHeader](/reference/system/xuser/structs/xusergettokenandsignaturehttpheader.md)
- [XUserGetTokenAndSignatureAsync](/reference/system/xuser/functions/xusergettokenandsignatureasync.md)
- [XUser](/reference/system/xuser/xuser_members.md)
