<?xml version="1.0" encoding="utf-8" standalone="yes"?><rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom"><channel><title>Curl on kenji.blog</title><link>http://kenji.blog/zh-tw/tags/curl/</link><description>Recent content in Curl on kenji.blog</description><generator>Hugo -- gohugo.io</generator><language>zh-tw</language><copyright>kenjinote</copyright><lastBuildDate>Mon, 07 Jul 2025 21:46:08 +0900</lastBuildDate><atom:link href="http://kenji.blog/zh-tw/tags/curl/index.xml" rel="self" type="application/rss+xml"/><item><title>【初學者指南】使用 vcpkg 在 Visual Studio 中安裝 libcurl（支援 OpenSSL）的步驟</title><link>http://kenji.blog/zh-tw/p/vcpkg-%E3%82%92%E4%BD%BF%E3%81%A3%E3%81%A6-visual-studio-%E3%81%AB-curl-%E3%82%92%E3%82%A4%E3%83%B3%E3%82%B9%E3%83%88%E3%83%BC%E3%83%AB/</link><pubDate>Mon, 07 Jul 2025 21:46:08 +0900</pubDate><guid>http://kenji.blog/zh-tw/p/vcpkg-%E3%82%92%E4%BD%BF%E3%81%A3%E3%81%A6-visual-studio-%E3%81%AB-curl-%E3%82%92%E3%82%A4%E3%83%B3%E3%82%B9%E3%83%88%E3%83%BC%E3%83%AB/</guid><description>&lt;img src="http://kenji.blog/p/vcpkg-%E3%82%92%E4%BD%BF%E3%81%A3%E3%81%A6-visual-studio-%E3%81%AB-curl-%E3%82%92%E3%82%A4%E3%83%B3%E3%82%B9%E3%83%88%E3%83%BC%E3%83%AB/img.png" alt="Featured image of post 【初學者指南】使用 vcpkg 在 Visual Studio 中安裝 libcurl（支援 OpenSSL）的步驟" />&lt;h2 id="如果您要在-visual-studio-中使用-libcurl支援-openssl強烈推薦引入-vcpkg非常簡單">如果您要在 Visual Studio 中使用 libcurl（支援 OpenSSL），強烈推薦引入 vcpkg，非常簡單
&lt;/h2>&lt;p>在 C++ 中處理 HTTP 通訊時，經常會使用 libcurl。但是，編譯和調整相依性卻意外地麻煩，對吧？&lt;/p>
&lt;p>這時候能派上用場的就是微軟開發的 C++ 函式庫管理工具 ** 「vcpkg」 ** 。
這次我們將介紹如何使用 cpkg 來引入 libcurl（支援 OpenSSL），並讓它在 Visual Studio 中能順暢使用的步驟。&lt;/p>
&lt;hr>
&lt;h3 id="vcpkg-的安裝僅限尚未安裝者">vcpkg 的安裝（僅限尚未安裝者）
&lt;/h3>&lt;p>首先，我們來安裝 cpkg. 請在 PowerShell 中執行以下步驟。&lt;/p>
&lt;p>&lt;code>powershell git clone https://github.com/microsoft/vcpkg cd vcpkg .ootstrap-vcpkg.bat &lt;/code>&lt;/p>
&lt;p>※如果您還沒安裝 Git，請到 &lt;a class="link" href="https://git-scm.com/" target="_blank" rel="noopener"
>Git 官方網站&lt;/a> 進行安裝。&lt;/p>
&lt;hr>
&lt;h3 id="libcurl支援-openssl的安裝">libcurl（支援 OpenSSL）的安裝
&lt;/h3>&lt;p>接著，使用 vcpkg 來安裝 libcurl. 為了指定支援 OpenSSL 的 64 位元版本，請執行以下命令。&lt;/p>
&lt;p>&lt;code>powershell vcpkg install curl[ssl] --triplet x64-windows &lt;/code>&lt;/p>
&lt;p>執行此命令後，必要的相依性（如 OpenSSL）也會被自動設定好。&lt;/p>
&lt;hr>
&lt;h3 id="與-visual-studio-的整合設定">與 Visual Studio 的整合設定
&lt;/h3>&lt;p>為了讓在 vcpkg 引入的函式庫能從 Visual Studio 專案中輕鬆使用，請使用下列命令進行整合設定。&lt;/p>
&lt;p>&lt;code>powershell vcpkg integrate install &lt;/code>&lt;/p>
&lt;p>設定好之後，在 Visual Studio 的專案中就能自動使用 #include &amp;lt;curl/curl.h&amp;gt;，不再需要手動設定函式庫的路徑或連結器。&lt;/p>
&lt;hr>
&lt;h2 id="結語">結語
&lt;/h2>&lt;p>至此，在 Visual Studio 中引入 libcurl（支援 OpenSSL）的準備工作就完成了。&lt;/p>
&lt;ul>
&lt;li>只要使用 vcpkg，就能一次管理所有麻煩的相依性&lt;/li>
&lt;li>使用 cpkg install curl[ssl] &amp;ndash;triplet x64-windows 輕鬆引入 libcurl&lt;/li>
&lt;li>使用 cpkg integrate install 即可與 Visual Studio 進行自動整合&lt;/li>
&lt;/ul>
&lt;p>接下來，只要在專案中包含標頭檔，並使用 libcurl 的 API 就能開始開發了。
請善用方便的 vcpkg，一口氣提升您的開發效率吧。&lt;/p></description></item><item><title>透過 curl 發送 Gmail</title><link>http://kenji.blog/zh-tw/p/%E9%80%8F%E9%81%8E-curl-%E7%99%BC%E9%80%81-gmail/</link><pubDate>Thu, 27 Feb 2025 02:13:31 +0900</pubDate><guid>http://kenji.blog/zh-tw/p/%E9%80%8F%E9%81%8E-curl-%E7%99%BC%E9%80%81-gmail/</guid><description>&lt;img src="http://kenji.blog/p/gmail%E3%82%92curl%E3%81%8B%E3%82%89%E9%80%81%E3%82%8B/img.png" alt="Featured image of post 透過 curl 發送 Gmail" />&lt;h1 id="透過-curl-發送-gmail">透過 curl 發送 Gmail
&lt;/h1>&lt;h2 id="1-取得應用程式密碼">1. 取得應用程式密碼
&lt;/h2>&lt;p>&lt;a class="link" href="https://myaccount.google.com/apppasswords" target="_blank" rel="noopener"
>https://myaccount.google.com/apppasswords&lt;/a>
點擊上方連結，並輸入應用程式名稱。
儲存產生的密碼。&lt;/p>
&lt;h2 id="2-使用-curl-指令發送電子郵件">2. 使用 curl 指令發送電子郵件
&lt;/h2>&lt;p>執行以下指令。&lt;/p>
&lt;p>在下面的範例中，郵件內容寫在 mail.txt 中。&lt;/p>
&lt;div class="highlight">&lt;div class="chroma">
&lt;table class="lntable">&lt;tr>&lt;td class="lntd">
&lt;pre tabindex="0" class="chroma">&lt;code>&lt;span class="lnt">1
&lt;/span>&lt;span class="lnt">2
&lt;/span>&lt;span class="lnt">3
&lt;/span>&lt;span class="lnt">4
&lt;/span>&lt;span class="lnt">5
&lt;/span>&lt;span class="lnt">6
&lt;/span>&lt;/code>&lt;/pre>&lt;/td>
&lt;td class="lntd">
&lt;pre tabindex="0" class="chroma">&lt;code class="language-mail.txt" data-lang="mail.txt">&lt;span class="line">&lt;span class="cl">From: from@gmail.com
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">To: to@gmail.com
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">Subject: 測試郵件
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">Content-Type: text/plain; charset=&amp;#34;UTF-8&amp;#34;
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">這是一封測試郵件。
&lt;/span>&lt;/span>&lt;/code>&lt;/pre>&lt;/td>&lt;/tr>&lt;/table>
&lt;/div>
&lt;/div>&lt;p>建立上述檔案後，執行以下指令。&lt;/p>
&lt;div class="highlight">&lt;div class="chroma">
&lt;table class="lntable">&lt;tr>&lt;td class="lntd">
&lt;pre tabindex="0" class="chroma">&lt;code>&lt;span class="lnt">1
&lt;/span>&lt;/code>&lt;/pre>&lt;/td>
&lt;td class="lntd">
&lt;pre tabindex="0" class="chroma">&lt;code class="language-bash" data-lang="bash">&lt;span class="line">&lt;span class="cl">curl --url &lt;span class="s2">&amp;#34;smtps://smtp.gmail.com:465&amp;#34;&lt;/span> --ssl-reqd --mail-from &lt;span class="s2">&amp;#34;from@gmail.com&amp;#34;&lt;/span> --mail-rcpt &lt;span class="s2">&amp;#34;to@gmail.com&amp;#34;&lt;/span> --user &lt;span class="s2">&amp;#34;from@gmail.com:xxxxxxxxxxxxxxxx&amp;#34;&lt;/span> --upload-file mail.txt
&lt;/span>&lt;/span>&lt;/code>&lt;/pre>&lt;/td>&lt;/tr>&lt;/table>
&lt;/div>
&lt;/div>&lt;p>※ 請將 xxxxxxxxxxxxxxxx 替換為您的應用程式密碼。&lt;/p></description></item><item><title>使用 curl 產生 QR Code</title><link>http://kenji.blog/zh-tw/p/curl%E3%81%A7qr%E3%82%B3%E3%83%BC%E3%83%89%E7%94%9F%E6%88%90/</link><pubDate>Tue, 16 Apr 2024 00:42:27 +0900</pubDate><guid>http://kenji.blog/zh-tw/p/curl%E3%81%A7qr%E3%82%B3%E3%83%BC%E3%83%89%E7%94%9F%E6%88%90/</guid><description>&lt;img src="http://kenji.blog/p/curl%E3%81%A7qr%E3%82%B3%E3%83%BC%E3%83%89%E7%94%9F%E6%88%90/img.png" alt="Featured image of post 使用 curl 產生 QR Code" />&lt;h2 id="使用-curl-產生-qr-code">使用 curl 產生 QR Code
&lt;/h2>&lt;p>注意：所介紹的方法是透過伺服器端產生 QR Code 並回傳，因此可能會被記錄日誌。將個人資訊等機密資訊轉換為 QR Code 時請多加留意。&lt;/p>
&lt;h3 id="方法-1">方法 1
&lt;/h3>&lt;p>這是在命令提示字元中產生 QR Code 的方法。
&lt;code>qrenco.de&lt;/code> 會以文字形式回傳結果。&lt;/p>
&lt;div class="highlight">&lt;div class="chroma">
&lt;table class="lntable">&lt;tr>&lt;td class="lntd">
&lt;pre tabindex="0" class="chroma">&lt;code>&lt;span class="lnt">1
&lt;/span>&lt;/code>&lt;/pre>&lt;/td>
&lt;td class="lntd">
&lt;pre tabindex="0" class="chroma">&lt;code class="language-fallback" data-lang="fallback">&lt;span class="line">&lt;span class="cl">curl qrenco.de/kenji.blog
&lt;/span>&lt;/span>&lt;/code>&lt;/pre>&lt;/td>&lt;/tr>&lt;/table>
&lt;/div>
&lt;/div>&lt;ul>
&lt;li>輸出結果&lt;/li>
&lt;/ul>
&lt;div class="highlight">&lt;div class="chroma">
&lt;table class="lntable">&lt;tr>&lt;td class="lntd">
&lt;pre tabindex="0" class="chroma">&lt;code>&lt;span class="lnt"> 1
&lt;/span>&lt;span class="lnt"> 2
&lt;/span>&lt;span class="lnt"> 3
&lt;/span>&lt;span class="lnt"> 4
&lt;/span>&lt;span class="lnt"> 5
&lt;/span>&lt;span class="lnt"> 6
&lt;/span>&lt;span class="lnt"> 7
&lt;/span>&lt;span class="lnt"> 8
&lt;/span>&lt;span class="lnt"> 9
&lt;/span>&lt;span class="lnt">10
&lt;/span>&lt;span class="lnt">11
&lt;/span>&lt;span class="lnt">12
&lt;/span>&lt;span class="lnt">13
&lt;/span>&lt;span class="lnt">14
&lt;/span>&lt;span class="lnt">15
&lt;/span>&lt;/code>&lt;/pre>&lt;/td>
&lt;td class="lntd">
&lt;pre tabindex="0" class="chroma">&lt;code class="language-fallback" data-lang="fallback">&lt;span class="line">&lt;span class="cl">█████████████████████████████
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">█████████████████████████████
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">████ ▄▄▄▄▄ █ ▄ ▄ █ ▄▄▄▄▄ ████
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">████ █ █ █ ▀▀▀██ █ █ ████
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">████ █▄▄▄█ █▀▀█▀▄█ █▄▄▄█ ████
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">████▄▄▄▄▄▄▄█▄▀ ▀ █▄▄▄▄▄▄▄████
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">████▄ █▀▄ ▄▀█▄▀ ▀██▄▀ ▄████
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">████▀▀▀█ ▄▄ ▄█▄█▀█▀▄██ ▀████
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">████▄▄▄██▄▄█ █▀█ ▄██▀▀█ █████
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">████ ▄▄▄▄▄ █▀█ ▀ ▄▀▄▄▄ ▀████
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">████ █ █ █▄▄ ▄▀▄▀▄ ██ ▀████
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">████ █▄▄▄█ █▀▀█ ▀▄▄▄ ▄▄██████
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">████▄▄▄▄▄▄▄█▄▄███▄▄█▄███▄████
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">█████████████████████████████
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">█████████████████████████████
&lt;/span>&lt;/span>&lt;/code>&lt;/pre>&lt;/td>&lt;/tr>&lt;/table>
&lt;/div>
&lt;/div>&lt;h4 id="參考">參考
&lt;/h4>&lt;ul>
&lt;li>&lt;a class="link" href="https://qrenco.de/" target="_blank" rel="noopener"
>qrenco.de&lt;/a>&lt;/li>
&lt;/ul>
&lt;h3 id="方法-2">方法 2
&lt;/h3>&lt;p>&lt;code>api.qrserver.com&lt;/code> 會回傳一張圖片。&lt;/p>
&lt;div class="highlight">&lt;div class="chroma">
&lt;table class="lntable">&lt;tr>&lt;td class="lntd">
&lt;pre tabindex="0" class="chroma">&lt;code>&lt;span class="lnt">1
&lt;/span>&lt;/code>&lt;/pre>&lt;/td>
&lt;td class="lntd">
&lt;pre tabindex="0" class="chroma">&lt;code class="language-fallback" data-lang="fallback">&lt;span class="line">&lt;span class="cl">curl -o qr.png &amp;#34;https://api.qrserver.com/v1/create-qr-code/?size=150x150&amp;amp;data=HelloWorld&amp;#34;
&lt;/span>&lt;/span>&lt;/code>&lt;/pre>&lt;/td>&lt;/tr>&lt;/table>
&lt;/div>
&lt;/div>&lt;ul>
&lt;li>輸出結果
&lt;img src="http://kenji.blog/p/curl%E3%81%A7qr%E3%82%B3%E3%83%BC%E3%83%89%E7%94%9F%E6%88%90/qr.png"
width="250"
height="250"
srcset="http://kenji.blog/p/curl%E3%81%A7qr%E3%82%B3%E3%83%BC%E3%83%89%E7%94%9F%E6%88%90/qr_hud34111b99823e39dfc62f9ba667fd5f9_390_480x0_resize_box_3.png 480w, http://kenji.blog/p/curl%E3%81%A7qr%E3%82%B3%E3%83%BC%E3%83%89%E7%94%9F%E6%88%90/qr_hud34111b99823e39dfc62f9ba667fd5f9_390_1024x0_resize_box_3.png 1024w"
loading="lazy"
class="gallery-image"
data-flex-grow="100"
data-flex-basis="240px"
>&lt;/li>
&lt;/ul>
&lt;h4 id="參考-1">參考
&lt;/h4>&lt;ul>
&lt;li>&lt;a class="link" href="https://goqr.me/api/doc/create-qr-code/" target="_blank" rel="noopener"
>QR Code Generator&lt;/a>&lt;/li>
&lt;/ul></description></item></channel></rss>