Components | All | New | MacOS | Windows | Linux | iOS | ||||
Examples | Mac & Win | Server | Client | Guides | Statistic | FMM | Blog | Deprecated | Old |
CURL.SetOptionURL
Sets the actual URL to deal with.
Component | Version | macOS | Windows | Linux | Server | iOS SDK |
CURL | 2.5 | ✅ Yes | ✅ Yes | ✅ Yes | ✅ Yes | ✅ Yes |
Parameters
Parameter | Description | Example | Flags |
---|---|---|---|
curl | The CURL session handle. | $curl | |
URL | The URL you want to use. | "http://www.mbsplugins.de/" | |
Encoding | The text encoding for text parameter. Default is UTF-8. Possible encoding names: ANSI, ISO-8859-1, Latin1, Mac, Native, UTF-8, DOS, Hex, Base64 or Windows. More listed in the FAQ. |
"utf8" | Optional |
Result
Returns "OK" on success.
Description
Sets the actual URL to deal with.If you want to include password and username, please use CURL.SetOptionUserName and CURL.SetOptionPassword instead of including them in the URL.
The parameter should be a text string which must be URL-encoded in the following format:
scheme://host:port/path
For a greater explanation of the format please see RFC 3986 (http://curl.haxx.se/rfc/rfc3986.txt).
If the given URL lacks the scheme, or protocol, part ("http://" or "ftp://" etc), libcurl will attempt to resolve which protocol to use based on the given host name. If the protocol is not supported, libcurl will return (CURLE_UNSUPPORTED_PROTOCOL) when you call CURL.Perform or CURL.PerformInBackground. Use CURL.Protocols for detailed information on which protocols are supported.
The host part of the URL contains the address of the server that you want to connect to. This can be the fully qualified domain name of the server, the local network name of the machine on your network or the IP address of the server or machine represented by either an IPv4 or IPv6 address. For example:
http://www.example.com/
http://hostname/
http://192.168.0.1/
http://[2001:1890:1112:1::20]/
It is also possible to specify the user name and password as part of the host, for some protocols, when connecting to servers that require authentication.
For example the following types of authentication support this:
http://user:password@www.domain.com ftp://user:password@ftp.domain.com pop3://user:password@mail.domain.com
The port is optional and when not specified libcurl will use the default port based on the determined or specified protocol: 80 for http, 21 for ftp and 25 for smtp, etc. The following examples show how to specify the port:
http://www.weirdserver.com:8080/ - This will connect to a web server using port 8080.
smtp://mail.domain.com:587/ - This will connect to a smtp server on the alternative mail port.
The path part of the URL is protocol specific and whilst some examples are given below this list is not conclusive:
HTTP
The path part of a HTTP request specifies the file to retrieve and from what directory. If the directory is not specified then the web server's root directory is used. If the file is omitted then the default document will be retrieved for either the directory specified or the root directory. The exact resource returned for each URL is entirely dependent on the server's configuration.
http://www.netscape.com - This gets the main page (index.html in this example) from Netscape's web server.
http://www.netscape.com/index.html - This returns the main page from Netscape by specifying the page to get.
http://www.netscape.com/contactus/ - This returns the default document from the contactus directory.
FTP
The path part of an FTP request specifies the file to retrieve and from what directory. If the file part is omitted then libcurl downloads the directory listing for the directory specified. If the directory is omitted then the directory listing for the root / home directory will be returned.
ftp://cool.haxx.se - This retrieves the directory listing for our FTP server.
ftp://cool.haxx.se/readme.txt - This downloads the file readme.txt from the root directory.
ftp://cool.haxx.se/libcurl/readme.txt - This downloads readme.txt from the libcurl directory.
ftp://user:password@my.example.com/readme.txt - This retrieves the readme.txt file from the user's home directory. When a username and password is specified, everything that is specified in the path part is relative to the user's home directory. To retrieve files from the root directory or a directory underneath the root directory then the absolute path must be specified by prepending an additional forward slash to the beginning of the path.
ftp://user:password@my.example.com//readme.txt - This retrieves the readme.txt from the root directory when logging in as a specified user.
SMTP
The path part of a SMTP request specifies the host name to present during communication with the mail server. If the path is omitted then libcurl will attempt to resolve the local computer's host name. However, this may not return the fully qualified domain name that is required by some mail servers and specifying this path allows you to set an alternative name, such as your machine's fully qualified domain name, which you might have obtained from an external function such as gethostname or getaddrinfo.
smtp://mail.domain.com - This connects to the mail server at domain.com and sends your local computer's host name in the HELO / EHLO command.
smtp://mail.domain.com/client.domain.com - This will send client.domain.com in the HELO / EHLO command to the mail server at domain.com.
POP3
The path part of a POP3 request specifies the mailbox (message) to retrieve. If the mailbox is not specified then a list of waiting messages is returned instead.
pop3://user:password@mail.domain.com - This lists the available messages pop3://user:password@mail.domain.com/1 - This retrieves the first message
SCP
The path part of an SCP request specifies the file to retrieve and from what directory. The file part may not be omitted. The file is taken as an absolute path from the root directory on the server. To specify a path relative to the user's home directory on the server, prepend ~/ to the path portion. If the user name is not embedded in the URL, it can be set with the CURL.SetOptionUserName option.
scp://user@example.com/etc/issue - This specifies the file /etc/issue
scp://example.com/~/my-file - This specifies the file my-file in the user's home directory on the server
SFTP
The path part of an SFTP request specifies the file to retrieve and from what directory. If the file part is omitted then libcurl downloads the directory listing for the directory specified. If the path ends in a / then a directory listing is returned instead of a file. If the path is omitted entirely then the directory listing for the root / home directory will be returned. If the user name is not embedded in the URL, it can be set with the SetOptionUsername option.
sftp://user:password@example.com/etc/issue - This specifies the file /etc/issue
sftp://user@example.com/~/my-file - This specifies the file my-file in the user's home directory
sftp://ssh.example.com/~/Documents/ - This requests a directory listing of the Documents directory under the user's home directory
NOTES
Starting with version 7.20.0, the fragment part of the URI will not be sent as part of the path, which was previously the case.
CURLOPT_URL is the only option that must be set before CURL.Preform or CURL.PerformInBackground is called.
CURLOPT_PROTOCOLS can be used to limit what protocols libcurl will use for this transfer, independent of what libcurl has been compiled to support. That may be useful if you accept the URL from an external source and want to limit the accessibility.
For file uploads or downloads, please include the file name in the URL.
Please do never include username and passwords in URLs, as those get often written to log files and would reveal your credentials!
Instead use OptionUsername and OptionPassword.
If you miss the protocol in the URL, you may get an error about HTTP/0.9 being used and not allowed.
See also URL option in CURL manual.
Examples
Set URL for FTP:
MBS( "CURL.SetOptionURL"; $curl; "ftp://user:password@my.example.com/readme.txt" )
Set URL for a REST API:
Set Variable [$r; MBS("CURL.SetOptionURL"; $curl; "https://example.com/wc-api/v2/products") ]
Query webservice with JSON request:
Set Variable [$curl; Value:MBS("CURL.New")]
Set Variable [$result; Value:MBS("CURL.SetOptionURL"; $curl; "http://test.test/ws/v1/catalogo/getmodelos")]
#pass JSON for query
Set Variable [$result; Value:MBS("CURL.SetOptionPostFields"; $curl; "{\"brandId\" : \"1\", \"device\" : \"70\"}"; "UTF-8")]
Set Field [models::result; MBS("CURL.Perform"; $curl)]
Set Field [models::text; MBS("CURL.GetResultAsText"; $curl;"UTF8")]
Set Field [models::header; MBS("CURL.GetDebugMessages"; $curl)]
Set Variable [$result; Value:MBS("CURL.Release"; $curl)]
Set URL for a POP3 email download:
Set Variable [$r; MBS("CURL.SetOptionURL"; $curl; "pop3://example.test") ]
Set URL for Gmail imap server:
Set Variable [$r; Value:MBS("CURL.SetOptionURL"; $curl; "imaps://imap.gmail.com/INBOX")]
Set Variable [$r; Value:MBS("CURL.SetOptionUseSSL"; $curl; 6)]
Set Variable [$r; Value:MBS("CURL.SetOptionPort"; $curl; 993)]
Set URL for a IMAP email download:
Set Variable [$r; MBS("CURL.SetOptionURL"; $curl; "imap://example.test") ]
# connect unencrypted and ask for TLS upgrade
Set Variable [$r; MBS("CURL.SetOptionUseSSL"; $curl; 3) ]
Set URL for a IMAP email download via SSL:
# connect with SSLv3 directly:
Set Variable [$r; MBS("CURL.SetOptionURL"; $curl; "imaps://example.test") ]
Setup IMAP for Office 365:
Set Variable [ $r ; Value: MBS("CURL.SetOptionURL"; $curl; "imaps://outlook.office365.com/INBOX") ]
Set Variable [ $r ; Value: MBS("CURL.SetOptionXOAuth2Bearer"; $curl; "eyJ0eXAiOi...") ] // your oAuth token
Set Variable [ $r ; Value: MBS("CURL.SetOptionUserName"; $curl; "test@outlook.com") ] // no password needed!
Load email list from gmail:
Go to Layout [ “IMAP Postbox” (IMAP Postbox) ; Animation: None ]
# get URL
Set Variable [ $URL ; Value: "imaps://imap.gmail.com/INBOX" ]
# query list of emails
Set Variable [ $curl ; Value: MBS("CURL.New") ]
Set Variable [ $r ; Value: MBS("CURL.SetOptionURL"; $curl; $URL) ]
Set Variable [ $r ; Value: MBS("CURL.SetOptionUserName"; $curl; IMAP Postbox::Username) ]
Set Variable [ $r ; Value: MBS("CURL.SetOptionPassword"; $curl; IMAP Postbox::Password) ]
Set Variable [ $result ; Value: MBS("CURL.SetOptionUseSSL"; $curl; 3) // required ]
Set Variable [ $result ; Value: MBS("CURL.SetOptionSSLVersion"; $curl; 6) // TLS v1.2 ]
Set Variable [ $result ; Value: MBS("CURL.SetOptionPort"; $curl; 993) ]
Set Variable [ $result ; Value: MBS("CURL.SetOptionConnectionTimeout"; $curl; 10) ]
# Set query for all emails by UID. Not all fields are needed. Only request those you need to make it quicker.
Set Variable [ $r ; Value: MBS("CURL.SetOptionCustomRequest"; $curl; "UID FETCH 1:* (FLAGS INTERNALDATE RFC822.SIZE BODY.PEEK[HEADER.FIELDS (Message-Id DATE FROM SUBJECT TO SENDER REPLY-TO CC BCC)])") ]
# Run transfer
Set Variable [ $result ; Value: MBS("CURL.Perform"; $curl) ]
# We show results for debugging
Set Variable [ $output ; Value: MBS("CURL.GetResultAsText"; $curl) ]
Set Variable [ $debug ; Value: MBS("CURL.GetDebugMessages"; $curl) ]
Set Variable [ $list ; Value: MBS( "JSON.Colorize";MBS("CURL.GetResultAsEMailList"; $curl)) ]
Set Variable [ $r ; Value: MBS("CURL.Release"; $curl) ]
Set Field [ IMAP Postbox::Log ; $debug ]
Set Field [ IMAP Postbox::JSON ; $list ]
Set URL for SFTP upload with file name in the URL:
MBS( "CURL.SetOptionURL"; $curl; "sftp://server.com/path/readme.txt" )
Set FTPS URL:
# URL for with ftps:// for FTP over SSL or ftp:// for TLS
Set Variable [$result; Value:MBS("CURL.SetOptionURL"; $curl; "ftps://test.com/test")]
# use TLS v1.2
Set Variable [$result; Value:MBS("CURL.SetOptionSSLVersion"; $curl; 6)]
# require SSL
Set Variable [$r; MBS( "CURL.SetOptionUseSSL"; $curl; 3 ) ]
Query emails via POP3 from GMail:
Set Variable [ $curl ; Value: MBS("CURL.New") ]
# use pop3s for SSL ehre
Set Variable [ $r ; Value: MBS("CURL.SetOptionURL"; $curl; "pop3s://pop.gmail.com/") ]
Set Variable [ $r ; Value: MBS("CURL.SetOptionUserName"; $curl; EmailClient::Username) ]
Set Variable [ $r ; Value: MBS("CURL.SetOptionPassword"; $curl; EmailClient::Password) ]
# set custom port. 995 is default for pop3 over SSL, so no need to set it
// Set Variable [ $r ; Value: MBS("CURL.SetOptionPort"; $curl; 995) ]
# we need TLS v1.2
Set Variable [ $r ; Value: MBS("CURL.SetOptionUseSSL"; $curl; 3) ]
Set Variable [ $r ; Value: MBS("CURL.SetOptionSSLVersion"; $curl; 6) ]
# and 10 second timeout
Set Variable [ $r ; Value: MBS("CURL.SetOptionConnectionTimeout"; $curl; 10) ]
Enocode file name for SFTP upload:
Set Variable [$EncodedFileName; Value: MBS( "Text.EncodeURLComponent"; $FileName; "utf-8" ) ]
Set Variable [$result; Value: MBS("CURL.SetOptionURL"; $curl; "ftps://test.com/test/" & $EncodedFileName )]
See also
- CURL.GetOptionURL
- CURL.SetOptionCRLF
- CURL.SetOptionDOHURL
- CURL.SetOptionRange
- CURL.SetOptionSASLIR
- CURL.SetOptionSSLKey
- JSON.Colorize
- JSON.GetPathItem
- SendMail.SetSMTPServer
- Text.EncodeURLComponent
Example Databases
- CURL/Batch Download
- CURL/CURL Download Text
- CURL/Email/Email Parser and Preview
- CURL/Email/IMAP Email List
- CURL/FTP/CURL FTP Download all Files in Directory
- CURL/FTP/CURL FTP Upload
- CURL/WebServices/CURL FMS Admin API v18
- CURL/WebServices/ebay webservice/ebay Webservice
- CURL/WebServices/WeatherBit.io test
- WebHook/WebHook Chat/WebHook Chat
Blog Entries
- Adding ChatGPT to the ScriptWorkspace context menu
- MQTT in FileMaker
- Background Log Custom function
- Parallel network transfers with MBS Plugin
- Send Audit Log via CURL in background
- How long do you wait for Insert From URL to finish?
- SFTP Upload with temporary file
- More follow up on oAuth for Office 365
- CURL Custom Function
- Trigger Scripts via WebHook
FileMaker Magazin
Created 18th August 2014, last changed 30th April 2024