Curl mac os установка

curl intro and installation

While Postman is convenient, it’s hard to use it to represent how to make calls with it in your documentation. Additionally, different users probably use different GUI clients, or none at all (preferring the command line instead).

Instead of describing how to make REST calls using a GUI client like Postman, the most conventional method for documenting request syntax is to use curl.

About curl

curl is a command-line utility that lets you execute HTTP requests with different parameters and methods. Instead of going to web resources in a browser’s address bar, you can use the command line to get these same resources, retrieved as text.

Sometimes curl is written as cURL. It stands for Client URL. “curl” is the more common convention for its spelling, but both refer to the same thing.

Installing curl

curl is usually available by default on Macs but requires some installation on Windows. Follow these instructions for installing curl:

Install curl on Mac

If you have a Mac, by default, curl is probably already installed. To check:

    Open Terminal (press Cmd + spacebar to open Stoplight, and then type “Terminal”).

In Terminal type curl -V . The response should look something like this:

If you don’t see this, you need to download and install curl.

Install curl on Windows

Installing curl on Windows involves a few more steps. First, determine whether you have 32-bit or 64-bit Windows by right-clicking Computer and selecting Properties. Then follow the instructions in this Confused by Code page. Most likely, you’ll want to choose the With Administrator Privileges (free) installer.

After you install curl, test your version of curl by doing the following:

  1. Open a command prompt by clicking the Start button and typing cmd.
  2. Type curl -V .

The response should be as follows:

Make a test API call

After you have curl installed, make a test API call:

(In the above code, replace APIKEY with your actual API key.)

You should get minified JSON response back like this:

In Windows, Ctrl+ V doesn’t work; instead, you right-click and then select Paste.

Notes about using curl with Windows

If you’re using Windows, note the following formatting requirements when using curl:

  • Use double quotes in the Windows command line. (Windows doesn’t support single quotes.)
  • Don’t use backslashes ( \ ) to separate lines. (This is for readability only and doesn’t affect the call on Macs.)
  • By adding -k in the curl command, you can bypass curl’s security certificate, which may or may not be necessary.

16/163 pages complete. Only 147 more pages to go.

Источник

Введение в curl и его установка

Хотя Postman удобен, его трудно использовать для представления в документации, как совершать запросы с его помощью. Кроме того, разные пользователи, вероятно, используют разные клиенты с графическим интерфейсом или вообще не используют их (предпочитая командную строку)

Вместо того, чтобы описывать, как выполнять REST-запросы с использованием GUI-клиента, такого как Postman, наиболее традиционный метод документирования синтаксиса запроса — использовать curl.

О curl

curl — это утилита командной строки, которая позволяет выполнять HTTP-запросы с различными параметрами и методами. Вместо того, чтобы переходить к веб-ресурсам в адресной строке браузера, можно использовать командную строку, чтобы получить те же ресурсы, извлеченные в виде текста.

Note: Иногда curl пишется как cURL, что означает Client URL.

curl является более распространенным написанием, так что оба варианта верны.

Установка curl

curl доступен на MacOS по умолчанию, для Windows требуется установка. Ниже представлены инструкции по установке curl.

Установка на MacOS

Проверить установлен ли curl на MacOS можно так:

  1. Открываем Терминал (нажимаем Cmd + spacebar для открытия Спотлайт и вводим Terminal).
  2. В терминале пишем curl -V . Ответ должен быть примерно таким:

Если такого ответа нет, то curl необходимо скачать и установить

Установка на Windows

Установка curl в Windows включает другие шаги. Сначала определяем версию windows: 32-разрядная или 64-разрядная версия Windows, щелкнув правой кнопкой мыши Компьютер и выбрав Свойства . Затем следуем инструкциям на этой странице. Нужно выбрать одну из бесплатных версий с правами Администратора.

После установки проверяем версию установленной curl;

  1. Открываем командную строку нажав кнопку Пуск и введя cmd
  2. В строке пишем curl -V

Ответ должен быть примерно таким:

Создание тестового вызова API

После установки curl делаем тестовый вызов API

В ответ должен вернуться минимизированный JSON:

curl и Windows

Если вы используете Windows, обратите внимание на следующие требования к форматированию при использовании curl:

  • Используйте двойные кавычки в командной строке Windows. (Windows не поддерживает одинарные кавычки.);
  • Не используйте обратную косую черту \ для разделения строк. (Это только для удобства чтения и не влияет на вызов на Mac.)
  • Добавив -k в команду curl, вы можете обойти сертификат безопасности curl, который может быть необходимым.

Источник

Learn how to install & run cURL on Windows/MacOSX/Linux

What is cURL?

cURL is a command-line tool that lets you transfer data to/from a server using various protocols. In this case, the curl command will establish a communication to POST or GET data to/from Ubidots Server over HTTP and HTTPS.

Below you will find the step-by-step to installing cURL in Windows, MacOSX and Linux.

Step-by-Step

1. Windows Installation

1. Enter and access the URL https://curl.haxx.se/ to download the curl executable wizard.

2. Select «curl executable» as Type of Package.

3. Then, on the «Select Operating System» section, select Windows. Then, continue selecting the parameters required based on your version of Windows.

4. Once you’ve finished the on-screen steps, download the zip file generated. To download it, simply press «Download«.

5. Next, open the .zip file and enter to the folder called «src*». Inside the src folder you will find the curl executable file. At this point, you need to copy the executable file and paste it inside a local folder on your PC to be able to run the curl.

Читайте также:  Как установить прозрачную панель задач windows 10

NOTE: To get a better understanding of the following steps, let’s assume the executable file is located inside a folder named «programs«.

6. From the Command Prompt, enter to the location where the executable file was pasted. To enter to the folder you need to use the cd command following the location of the folder which contains the executable file as you can see below.

Expected location to be shown

7. To verify if you are able to run curl commands with the command prompt, test functionality by executing the command below:

At this point, you should receive the all the help info related to the curl command.

[Troubleshooting] If you experience errors in the downloading process, please refer to this video for additional troubleshooting.

Now you are able to use cURL from your Windows pc!

2. MacOSX Installation

1. Enter to the computer’s terminal.

2. Run the command below in the terminal:

3. If a password is required after running the command, please enter your Mac’s user password to continue. Then, wait until the installation finish.

4. Run the command below in the terminal:

Now you are able to use cURL from your Mac pc!

3. Linux installation

1. Enter to the computer’s terminal.

2. Run the command below in the terminal:

3. If a password is required after ran the command, please enter your computers’ user password to continue. Then, wait until the installation finishes.

Now you are able to use cURL from your Linux pc!

Источник

Using cURL with HTTP/2 on Mac OS X

cURL is one of the most powerful tool for testing HTTP requests and responses. Most developers use curl to interact with HTTP APIs or to test a website.

Starting from version 7.43.0 cURL (and libcurl ) supports HTTP/2. You can perform a request using the HTTP/2 protocol passing the —http2 flag:

However, in order to support HTTP/2, cURL must be linked to nghttp and the default cURL version shipped with Mac OS X does not. As a result, if you try to pass the —http2 flag you’ll receive the following error:

To solve the issue and use cURL with HTTP/2 in Mac OS X your need to recompile cURL. This is a very easy task if you use Homebrew. Thanks to this PR you can reinstall cURL via Homebrew and pass the —with-nghttp2 flag to add the HTTP/2 support along with the necessary dependencies.

Almost done. By default, Homebrew will not replace the curl binary shipped with Mac OS X, therefore you need to explicitly «link» it if you want to use the new version without specifying the entire path to the binary (which by the way is /usr/local/Cellar/curl/7.46.0/bin/curl ):

Close/reopen the shell and the curl location should now be:

You can also confirm the version and the custom flag using the command brew info curl :

If it’s still /usr/bin/curl then make sure cURL was properly installed via Homebrew and you restarted your shell.

Instructions

To recap, here’s the list of commands to compile and install cURL with HTTP/2 support in Mac OS X using Homebrew:

A special thanks to Daniel Stenberg for cURL, and to @felixbuenemann for the Homebrew patch that made it possible to install cURL with HTTP/2 with zero effort.

Источник

how to install curl and libcurl

Installing Binary Packages

Lots of people download binary distributions of curl and libcurl. This document does not describe how to install curl or libcurl using such a binary package. This document describes how to compile, build and install curl and libcurl from source code.

Building using vcpkg

You can download and install curl and libcurl using the vcpkg dependency manager:

The curl port in vcpkg is kept up to date by Microsoft team members and community contributors. If the version is out of date, please create an issue or pull request on the vcpkg repository.

Building from git

If you get your code off a git repository instead of a release tarball, see the GIT-INFO file in the root directory for specific instructions on how to proceed.

A normal Unix installation is made in three or four steps (after you’ve unpacked the source archive):

(Adjust the configure line accordingly to use the TLS library you want.)

You probably need to be root when doing the last command.

Get a full listing of all available configure options by invoking it like:

If you want to install curl in a different file hierarchy than /usr/local , specify that when running configure:

If you have write permission in that directory, you can do ‘make install’ without being root. An example of this would be to make a local install in your own home directory:

The configure script always tries to find a working SSL library unless explicitly told not to. If you have OpenSSL installed in the default search path for your compiler/linker, you don’t need to do anything special. If you have OpenSSL installed in /usr/local/ssl , you can run configure like:

If you have OpenSSL installed somewhere else (for example, /opt/OpenSSL ) and you have pkg-config installed, set the pkg-config path first, like this:

Without pkg-config installed, use this:

If you insist on forcing a build without SSL support, even though you may have OpenSSL installed in your system, you can run configure like this:

If you have OpenSSL installed, but with the libraries in one place and the header files somewhere else, you have to set the LDFLAGS and CPPFLAGS environment variables prior to running configure. Something like this should work:

If you have shared SSL libs installed in a directory where your run-time linker doesn’t find them (which usually causes configure failures), you can provide this option to gcc to set a hard-coded path to the run-time linker:

More Options

To force a static library compile, disable the shared library creation by running configure like:

To tell the configure script to skip searching for thread-safe functions, add an option like:

If you’re a curl developer and use gcc, you might want to enable more debug options with the —enable-debug option.

curl can be built to use a whole range of libraries to provide various useful services, and configure will try to auto-detect a decent default. But if you want to alter it, you can select how to deal with each individual library.

Читайте также:  Net core windows server hosting bundle

Select TLS backend

These options are provided to select TLS backend to use.

  • AmiSSL: —with-amissl
  • BearSSL: —with-bearssl
  • GnuTLS: —with-gnutls .
  • mbedTLS: —with-mbedtls
  • MesaLink: —with-mesalink
  • NSS: —with-nss
  • OpenSSL: —with-openssl (also for BoringSSL and libressl)
  • rustls: —with-rustls
  • schannel: —with-schannel
  • secure transport: —with-secure-transport
  • wolfSSL: —with-wolfssl

Windows

Building Windows DLLs and C run-time (CRT) linkage issues

As a general rule, building a DLL with static CRT linkage is highly discouraged, and intermixing CRTs in the same app is something to avoid at any cost.

Reading and comprehending Microsoft Knowledge Base articles KB94248 and KB140584 is a must for any Windows developer. Especially important is full understanding if you are not going to follow the advice given above.

If your app is misbehaving in some strange way, or it is suffering from memory corruption, before asking for further help, please try first to rebuild every single library your app uses as well as your app using the debug multithreaded dynamic C runtime.

If you get linkage errors read section 5.7 of the FAQ document.

MingW32

Make sure that MinGW32’s bin dir is in the search path, for example:

then run mingw32-make mingw32 in the root dir. There are other make targets available to build libcurl with more features, use:

  • mingw32-make mingw32-zlib to build with Zlib support;
  • mingw32-make mingw32-ssl-zlib to build with SSL and Zlib enabled;
  • mingw32-make mingw32-ssh2-ssl-zlib to build with SSH2, SSL, Zlib;
  • mingw32-make mingw32-ssh2-ssl-sspi-zlib to build with SSH2, SSL, Zlib and SSPI support.

If you have any problems linking libraries or finding header files, be sure to verify that the provided Makefile.m32 files use the proper paths, and adjust as necessary. It is also possible to override these paths with environment variables, for example:

It is also possible to build with other LDAP SDKs than MS LDAP; currently it is possible to build with native Win32 OpenLDAP, or with the Novell CLDAP SDK. If you want to use these you need to set these vars:

or for using the Novell SDK:

If you want to enable LDAPS support then set LDAPS=1.

Cygwin

Almost identical to the unix installation. Run the configure script in the curl source tree root with sh configure . Make sure you have the sh executable in /bin/ or you’ll see the configure fail toward the end.

Disabling Specific Protocols in Windows builds

The configure utility, unfortunately, is not available for the Windows environment, therefore, you cannot use the various disable-protocol options of the configure utility on this platform.

You can use specific defines to disable specific protocols and features. See CURL-DISABLE.md for the full list.

If you want to set any of these defines you have the following options:

  • Modify lib/config-win32.h
  • Modify lib/curl_setup.h
  • Modify winbuild/Makefile.vc
  • Modify the «Preprocessor Definitions» in the libcurl project

Note: The pre-processor settings can be found using the Visual Studio IDE under «Project -> Settings -> C/C++ -> General» in VC6 and «Project -> Properties -> Configuration Properties -> C/C++ -> Preprocessor» in later versions.

Using BSD-style lwIP instead of Winsock TCP/IP stack in Win32 builds

In order to compile libcurl and curl using BSD-style lwIP TCP/IP stack it is necessary to make definition of preprocessor symbol USE_LWIPSOCK visible to libcurl and curl compilation processes. To set this definition you have the following alternatives:

  • Modify lib/config-win32.h and src/config-win32.h
  • Modify winbuild/Makefile.vc
  • Modify the «Preprocessor Definitions» in the libcurl project

Note: The pre-processor settings can be found using the Visual Studio IDE under «Project -> Settings -> C/C++ -> General» in VC6 and «Project -> Properties -> Configuration Properties -> C/C++ -> Preprocessor» in later versions.

Once that libcurl has been built with BSD-style lwIP TCP/IP stack support, in order to use it with your program it is mandatory that your program includes lwIP header file (or another lwIP header that includes this) before including any libcurl header. Your program does not need the USE_LWIPSOCK preprocessor definition which is for libcurl internals only.

Compilation has been verified with lwIP 1.4.0 and contrib-1.4.0.

This BSD-style lwIP TCP/IP stack support must be considered experimental given that it has been verified that lwIP 1.4.0 still needs some polish, and libcurl might yet need some additional adjustment, caveat emptor.

Important static libcurl usage note

When building an application that uses the static libcurl library on Windows, you must add -DCURL_STATICLIB to your CFLAGS . Otherwise the linker will look for dynamic import symbols.

Legacy Windows and SSL

Schannel (from Windows SSPI), is the native SSL library in Windows. However, Schannel in Windows —with-secure-transport . (It is not necessary to use the option —without-openssl .)

When Secure Transport is in use, the curl options —cacert and —capath and their libcurl equivalents, will be ignored, because Secure Transport uses the certificates stored in the Keychain to evaluate whether or not to trust the server. This, of course, includes the root certificates that ship with the OS. The —cert and —engine options, and their libcurl equivalents, are currently unimplemented in curl with Secure Transport.

In general, a curl build for an Apple ARCH/SDK/DEPLOYMENT_TARGET combination can be taken by providing appropriate values for ARCH , SDK , DEPLOYMENT_TARGET below and running the commands:

Above will build curl for macOS platform with x86_64 architecture and 10.8 as deployment target.

Here is an example for iOS device:

Another example for watchOS simulator for macs with Apple Silicon:

In all above, the built libraries and executables can be found in artifacts folder.

Android

When building curl for Android it’s recommended to use a Linux environment since using curl’s configure script is the easiest way to build curl for Android. Before you can build curl for Android, you need to install the Android NDK first. This can be done using the SDK Manager that is part of Android Studio. Once you have installed the Android NDK, you need to figure out where it has been installed and then set up some environment variables before launching configure . On macOS, those variables could look like this to compile for aarch64 and API level 29:

When building on Linux or targeting other API levels or architectures, you need to adjust those variables accordingly. After that you can build curl like this:

Note that this won’t give you SSL/TLS support. If you need SSL/TLS, you have to build curl against a SSL/TLS layer, e.g. OpenSSL, because it’s impossible for curl to access Android’s native SSL/TLS layer. To build curl for Android using OpenSSL, follow the OpenSSL build instructions and then install libssl.a and libcrypto.a to $TOOLCHAIN/sysroot/usr/lib and copy include/openssl to $TOOLCHAIN/sysroot/usr/include . Now you can build curl for Android using OpenSSL like this:

Читайте также:  How to change home directory linux

Note, however, that you must target at least Android M (API level 23) or configure won’t be able to detect OpenSSL since stderr (and the like) weren’t defined before Android M.

IBM i

For IBM i (formerly OS/400), you can use curl in two different ways:

  • Natively, running in the ILE. The obvious use is being able to call curl from ILE C or RPG applications.
    • You will need to build this from source. See packages/OS400/README for the ILE specific build instructions.
  • In the PASE environment, which runs AIX programs. curl will be built as it would be on AIX.
    • IBM provides builds of curl in their Yum repository for PASE software.
    • To build from source, follow the Unix instructions.

There are some additional limitations and quirks with curl on this platform; they affect both environments.

Multithreading notes

By default, jobs in IBM i won’t start with threading enabled. (Exceptions include interactive PASE sessions started by QP2TERM or SSH.) If you use curl in an environment without threading when options like async DNS were enabled, you’ll messages like:

Don’t panic! curl and your program aren’t broken. You can fix this by:

  • Set the environment variable QIBM_MULTI_THREADED to Y before starting your program. This can be done at whatever scope you feel is appropriate.
  • Alternatively, start the job with the ALWMLTTHD parameter set to *YES .

Cross compile

Download and unpack the curl package.

cd to the new directory. (e.g. cd curl-7.12.3 )

Set environment variables to point to the cross-compile toolchain and call configure with any options you need. Be sure and specify the —host and —build parameters at configuration time. The following script is an example of cross-compiling for the IBM 405GP PowerPC processor using the toolchain from MonteVista for Hardhat Linux.

You may also need to provide a parameter like —with-random=/dev/urandom to configure as it cannot detect the presence of a random number generating device for a target system. The —prefix parameter specifies where curl will be installed. If configure completes successfully, do make and make install as usual.

In some cases, you may be able to simplify the above commands to as little as:

REDUCING SIZE

There are a number of configure options that can be used to reduce the size of libcurl for embedded applications where binary size is an important factor. First, be sure to set the CFLAGS variable when configuring with any relevant compiler optimization flags to reduce the size of the binary. For gcc, this would mean at minimum the -Os option, and potentially the -march=X , -mdynamic-no-pic and -flto options as well, e.g.

Note that newer compilers often produce smaller code than older versions due to improved optimization.

Be sure to specify as many —disable- and —without- flags on the configure command-line as you can to disable all the libcurl features that you know your application is not going to need. Besides specifying the —disable-PROTOCOL flags for all the types of URLs your application will not use, here are some other flags that can reduce the size of the library:

  • —disable-ares (disables support for the C-ARES DNS library)
  • —disable-cookies (disables support for HTTP cookies)
  • —disable-crypto-auth (disables HTTP cryptographic authentication)
  • —disable-ipv6 (disables support for IPv6)
  • —disable-manual (disables support for the built-in documentation)
  • —disable-proxy (disables support for HTTP and SOCKS proxies)
  • —disable-unix-sockets (disables support for UNIX sockets)
  • —disable-verbose (eliminates debugging strings and error code strings)
  • —disable-versioned-symbols (disables support for versioned symbols)
  • —enable-hidden-symbols (eliminates unneeded symbols in the shared library)
  • —without-libidn (disables support for the libidn DNS library)
  • —without-librtmp (disables support for RTMP)
  • —without-openssl (disables support for SSL/TLS)
  • —without-zlib (disables support for on-the-fly decompression)

The GNU compiler and linker have a number of options that can reduce the size of the libcurl dynamic libraries on some platforms even further. Specify them by providing appropriate CFLAGS and LDFLAGS variables on the configure command-line, e.g.

Be sure also to strip debugging symbols from your binaries after compiling using ‘strip’ (or the appropriate variant if cross-compiling). If space is really tight, you may be able to remove some unneeded sections of the shared library using the -R option to objcopy (e.g. the .comment section).

Using these techniques it is possible to create a basic HTTP-only shared libcurl library for i386 Linux platforms that is only 113 KiB in size, and an FTP-only library that is 113 KiB in size (as of libcurl version 7.50.3, using gcc 5.4.0).

You may find that statically linking libcurl to your application will result in a lower total size than dynamically linking.

Note that the curl test harness can detect the use of some, but not all, of the —disable statements suggested above. Use will cause tests relying on those features to fail. The test harness can be manually forced to skip the relevant tests by specifying certain key words on the runtests.pl command line. Following is a list of appropriate key words:

  • —disable-cookies !cookies
  • —disable-manual !—manual
  • —disable-proxy !HTTP\ proxy !proxytunnel !SOCKS4 !SOCKS5

PORTS

This is a probably incomplete list of known CPU architectures and operating systems that curl has been compiled for. If you know a system curl compiles and runs on, that isn’t listed, please let us know!

85 Operating Systems

AIX, AmigaOS, Android, Aros, BeOS, Blackberry 10, Blackberry Tablet OS, Cell OS, ChromeOS, Cisco IOS, Cygwin, Dragonfly BSD, eCOS, FreeBSD, FreeDOS, FreeRTOS, Fuchsia, Garmin OS, Genode, Haiku, HardenedBSD, HP-UX, Hurd, Illumos, Integrity, iOS, ipadOS, IRIX, LineageOS, Linux, Lua RTOS, Mac OS 9, macOS, Mbed, Micrium, MINIX, MorphOS, MPE/iX, MS-DOS, NCR MP-RAS, NetBSD, Netware, Nintendo Switch, NonStop OS, NuttX, OpenBSD, OpenStep, Orbis OS, OS/2, OS/400, OS21, Plan 9, PlayStation Portable, QNX, Qubes OS, ReactOS, Redox, RICS OS, Sailfish OS, SCO Unix, Serenity, SINIX-Z, Solaris, SunOS, Syllable OS, Symbian, Tizen, TPF, Tru64, tvOS, ucLinux, Ultrix, UNICOS, UnixWare, VMS, vxWorks, WebOS, Wii system software, Windows, Windows CE, Xbox System, z/OS, z/TPF, z/VM, z/VSE

22 CPU Architectures

Alpha, ARC, ARM, AVR32, Cell, HP-PA, Itanium, m68k, MicroBlaze, MIPS, Nios, OpenRISC, POWER, PowerPC, RISC-V, s390, SH4, SPARC, VAX, x86, x86-64, Xtensa

Источник

Оцените статью