CURL.ReceiveText
----------------

Receives raw data on a connection as text.

| Component | Version | macOS | Windows | Linux | Server | iOS SDK |
|---|---|---|---|---|---|---|
| [CURL](component_CURL.md) | [7.2](newinversion72.md) | ✅ Yes | ✅ Yes | ✅ Yes | ✅ Yes | ✅ Yes |

MBS( "CURL.ReceiveText"; curl; BytesToRead { ; Encoding } ) 

**MBS**( **"CURL.ReceiveText";** /\* Receives raw data on a connection as text. \*/  
**$curl**; /\* The CURL session handle. \*/   
**$BytesToRead**; /\* Maximum number of bytes to read.e.g. 1000 \*/   
**$Encoding**) /\* Optional; The text encoding for result.  
Default is UTF-8.e.g. "UTF8" \*/ 

### Parameters

| Parameter | Description | Example | Flags |
|---|---|---|---|
| curl | The CURL session handle. | $curl |  |
| BytesToRead | Maximum number of bytes to read. | 1000 |  |
| Encoding | The text encoding for result.   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](https://www.monkeybreadsoftware.com/filemaker/faq.shtml). | "UTF8" | Optional |

### Result

Returns text or error.

### Description

Receives raw data on a connection as text.  
This function receives raw data from the established connection. You may use it together with SendData to implement custom protocols using libcurl. This functionality can be particularly useful if you use proxies and/or SSL encryption: libcurl will take care of proxy negotiation and connection set-up.  
  
BytesToRead is the maximum amount of data you want to read now. The function returns the text read, which can be less than requested.  
  
To establish the connection, set OptionConnectOnly = true before calling Perform. Note that ReceiveData does not work on connections that were created without this option.  
  
The call will return CURLE\_AGAIN if there is no data to read - the socket is used in non-blocking mode internally. When CURLE\_AGAIN is returned, wait for data to arrive.  
  
Wait on the socket only if ReceiveData returns CURLE\_AGAIN. The reason for this is libcurl or the SSL library may internally cache some data, therefore you should call ReceiveData until all data is read which would include any cached data.  
  
Furthermore if you wait on the socket and it tells you there is data to read, ReceiveData may return CURLE\_AGAIN if the only data that was read was for internal SSL processing, and no other data is available.  
  
On success, sets error code to CURLE\_OK (0) and returns the text.  
On failure, returns zero and error code is set to the appropriate error code.  
  
The function may return CURLE\_AGAIN. In this case, use your operating system facilities to wait until data can be read, and retry.  
  
Reading exactly 0 bytes indicates a closed connection.  
  
If there's no socket available to use from the previous transfer, this function returns CURL\_EUNSUPPORTED\_PROTOCOL.  
  
Please use [CURL.ErrorCode](CURLErrorCode.md) to query error after you used this function.  
### Examples

Loop and read text from socket:

 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](CURLErrorCode.md)"; $curl )\]  
 If \[GetAsNumber ( $errorCode ) = 81\]  
 #wait  
 Else If \[GetAsNumber ( $errorCode ) = 0\]  
 #got some data  
 Set Variable \[$received ; Value:$received &amp; $r \]  
 Exit Loop If \[$r = ""\]  
 Else  
 #error  
 Exit Loop If \[1\]  
 End If  
 End Loop  
 Set Variable \[$received2 ; Value:MBS ( "[Text.ReplaceNewLine](TextReplaceNewLine.md)"; $received ; 1)\]  
 Set Field \[CURL Low Level Sockets::Data Received; $received2 \]  
### See also

- [CURL.ErrorCode](CURLErrorCode.md)
- [CURL.ReceiveData](CURLReceiveData.md)
- [CURL.SetOptionConnectOnly](CURLSetOptionConnectOnly.md)
- [Socket.SSL.Connect](SocketSSLConnect.md)
- [Socket.SSL.Initialize](SocketSSLInitialize.md)
- [Text.ReplaceNewLine](TextReplaceNewLine.md)

### Release notes

- **Version 7.2**
    - Added [CURL.ReceiveData](http://www.mbsplugins.eu/CURLReceiveData.shtml), [CURL.ReceiveText](http://www.mbsplugins.eu/CURLReceiveText.shtml), [CURL.SendData](http://www.mbsplugins.eu/CURLSendData.shtml) and [CURL.SendText](http://www.mbsplugins.eu/CURLSendText.shtml) to send data over a CURL connected socket.

### Example Databases

- [CURL/CURL Low Level Sockets](https://www.mbsplugins.eu/MBS-FileMaker-Plugin-Examples/CURL/CURL%20Low%20Level%20Sockets.shtml#2ScriptAnchor_)

### Blog Entries

- [Socket changes for MBS FileMaker Plugin](https://www.mbsplugins.de/archive/2020-08-31/Socket_changes_for_MBS_FileMak/monkeybreadsoftware_blog_filemaker)
- [MBS FileMaker Plugin, version 7.2pr1](https://www.mbsplugins.de/archive/2017-04-03/MBS_FileMaker_Plugin_version_7/monkeybreadsoftware_blog_filemaker)

This function checks for a license.

Created 27th March 2017 , last changed 9th November 2021

  
[CURL.ReceiveData](CURLReceiveData.md) - [CURL.Release](CURLRelease.md)

[HTML Version](CURLReceiveText.shtml)