Components | All | New | MacOS | Windows | Linux | iOS | ||||
Examples | Mac & Win | Server | Client | Guides | Statistic | FMM | Blog | Deprecated | Old |
CURL.SetOptionConnectOnly
Connect only.
Component | Version | macOS | Windows | Linux | Server | iOS SDK |
CURL | 7.2 | ✅ Yes | ✅ Yes | ✅ Yes | ✅ Yes | ✅ Yes |
Parameters
Parameter | Description | Example |
---|---|---|
curl | The CURL session handle. | $curl |
Value | The option value. |
Result
Returns OK or error.
Description
Connect only.A 1 tells the library to perform any required proxy authentication and connection setup, but no data transfer.
Use this option to tell CURL to connect only and then send/receive data with your own protocol.
See CURL.SendData, CURL.SendText, CURL.ReceiveText and CURL.ReceiveData.
Since 7.86.0, this option can be set to '2' and if HTTP or WebSocket are used, CURL will do the request and read all response headers before handing over control to the application.
Transfers marked connect only will not reuse any existing connections and connections marked connect only will not be allowed to get reused.
See also CONNECT_ONLY option in CURL manual.
Examples
Download website and handle protocol ourself:
#Start new session
Set Variable [$curl; Value:MBS("CURL.New")]
#Set URL to load (HTTP, HTTPS, FTP, FTPS, SFTP, etc.)
Set Variable [$result; Value:MBS("CURL.SetOptionConnectOnly"; $curl; 1)]
Set Variable [$result; Value:MBS("CURL.SetOptionURL"; $curl; CURL Low Level Sockets::URL)]
Set Variable [$request; Value:"GET / HTTP/1.1¶Host: www.monkeybreadsoftware.com¶¶" // must end with two empty lines ]
Set Variable [$request2; Value:MBS( "Text.ReplaceNewline"; $request; 3)]
#RUN now
Set Field [CURL Low Level Sockets::Connect Result; MBS("CURL.Perform"; $curl)]
#Check result
Set Field [CURL Low Level Sockets::Data Received; MBS("CURL.GetResultAsText"; $curl; "UTF8")]
Set Field [CURL Low Level Sockets::Debug Messages; MBS("CURL.GetDebugMessages"; $curl)]
If [CURL Low Level Sockets::Connect Result = "OK"]
Set Variable [$r; Value:MBS( "CURL.SendText"; $curl; $request2; "UTF-8")]
Set Field [CURL Low Level Sockets::Data Sent; $request]
Set Variable [$received; Value:""]
Loop
Pause/Resume Script [Duration (seconds): ,1]
Set Variable [$r; Value:MBS( "CURL.ReceiveText"; $curl; 100000; "UTF-8")]
Set Variable [$errorCode; Value:MBS( "CURL.ErrorCode"; $curl)]
If [GetAsNumber ( $errorCode ) = 81]
#wait
Else If [GetAsNumber ( $errorCode ) = 0]
#got some data
Set Variable [$received; Value:$received & $r]
Exit Loop If [$r = ""]
Else
#error
Exit Loop If [1]
End If
End Loop
Set Variable [$received2; Value:MBS( "Text.ReplaceNewline"; $received; 1)]
Set Field [CURL Low Level Sockets::Debug Messages; MBS("CURL.GetDebugMessages"; $curl)]
Set Field [CURL Low Level Sockets::Data Received; $received2]
End If
#Cleanup
Set Variable [$result; Value:MBS("CURL.Release"; $curl)]
Check if SMB (port 445) is open on a given IP in network:
Let ( [
curl = MBS("CURL.New");
a = MBS( "CURL.SetOptionConnectOnly"; curl; 1 );
b = MBS( "CURL.SetOptionURL"; curl; "192.168.2.117" );
c = MBS( "CURL.SetOptionConnectionTimeout"; curl; 1 );
d = MBS( "CURL.SetOptionPort"; curl; 445 );
r = MBS( "CURL.Perform"; curl );
x = MBS( "CURL.Release"; curl)
]; r )
// returns either
// OK
// or
// 28: Connection timed out after 1000 milliseconds
Try whether google is available:
Let ( [
# new session
curl = MBS("CURL.New");
# only connect, don't transfer data
r = MBS("CURL.SetOptionConnectOnly"; curl; 1);
# limit time to 1 second to connect and 2 seconds in total
r = MBS("CURL.SetOptionConnectionTimeout"; curl; 1);
r = MBS("CURL.SetOptionTimeOut"; curl; 2);
# new connection please
r = MBS("CURL.SetOptionFreshConnect"; curl; 1);
r = MBS("CURL.SetOptionForbidReuse"; curl; 1);
# we query google here
r = MBS("CURL.SetOptionURL"; curl; "http://www.google.de");
# and try it!
result = MBS("CURL.Perform"; curl);
# optionally have log messages go there
// $$log = MBS("CURL.GetDebugMessages"; curl);
# and cleanup
r = MBS("CURL.Release"; curl)
]; result )
See also
- CURL.GetOptionConnectTo
- CURL.SetOptionConnectionTimeout
- CURL.SetOptionConnectTo
- CURL.SetOptionDirListOnly
- CURL.SetOptionMaxConnects
- CURL.SetOptionTimeOut
- CURL.SetOptionURL
- Socket.SSL.Connect
- Socket.SSL.Initialize
- Text.ReplaceNewline
Example Databases
Blog Entries
Created 27th March 2017, last changed 4th March 2023