emptygif
ภาษา: ไทย

ภาษาและเฟรมเวิร์กทั้งหมด

Pode PowerShell

ตัวอย่างโค้ด PowerShell สำหรับ Pode ที่ตอบคำขอไปยัง /pixel.gif ด้วย GIF ว่าง ซึ่งถอดรหัสเพียงครั้งเดียวตอนเริ่มทำงาน

Pode PowerShell

ติดตั้ง
Install-Module -Name Pode
ไฟล์
server.ps1
รัน
pwsh ./server.ps1
Import-Module Pode

Start-PodeServer {
    Add-PodeEndpoint -Address * -Port 8080 -Protocol Http
    Set-PodeState -Name 'Gif' -Value ([Convert]::FromBase64String('R0lGODlhAQABAIAAAP///wAAACH5BAEAAAAALAAAAAABAAEAAAICRAEAOw==')) | Out-Null

    Add-PodeRoute -Method Get -Path '/pixel.gif' -ScriptBlock {
        Set-PodeHeader -Name 'Cache-Control' -Value 'no-store'
        # Pode appends '; charset=utf-8' to the type; browsers ignore it for images.
        Write-PodeTextResponse -Bytes (Get-PodeState -Name 'Gif') -ContentType 'image/gif'
    }
}

เรารันตัวอย่างโค้ดนี้และเทียบไบต์ที่ได้กลับมาแล้ว

ตรวจสอบ

curl -sI http://localhost:8080/pixel.gif

เว็บไซต์ทางการ: Pode

เพิ่มเติมใน PowerShell