CONTENTTYPE_NONE = ''; // do not localize
// Type Application
CONTENTTYPE_APPLICATION_ATOM_XML = 'application/atom+xml'; // do not localize
CONTENTTYPE_APPLICATION_ECMASCRIPT = 'application/ecmascript'; // do not localize
CONTENTTYPE_APPLICATION_EDI_X12 = 'application/EDI-X12'; // do not localize
CONTENTTYPE_APPLICATION_EDIFACT = 'application/EDIFACT'; // do not localize
CONTENTTYPE_APPLICATION_JSON = 'application/json'; // do not localize
CONTENTTYPE_APPLICATION_JAVASCRIPT = 'application/javascript'; // do not localize
CONTENTTYPE_APPLICATION_OCTET_STREAM = 'application/octet-stream'; // do not localize
CONTENTTYPE_APPLICATION_OGG = 'application/ogg'; // do not localize
CONTENTTYPE_APPLICATION_PDF = 'application/pdf'; // do not localize
CONTENTTYPE_APPLICATION_POSTSCRIPT = 'application/postscript'; // do not localize
CONTENTTYPE_APPLICATION_RDF_XML = 'application/rdf+xml'; // do not localize
CONTENTTYPE_APPLICATION_RSS_XML = 'application/rss+xml'; // do not localize
CONTENTTYPE_APPLICATION_SOAP_XML = 'application/soap+xml'; // do not localize
CONTENTTYPE_APPLICATION_FONT_WOFF = 'application/font-woff'; // do not localize
CONTENTTYPE_APPLICATION_XHTML_XML = 'application/xhtml+xml'; // do not localize
CONTENTTYPE_APPLICATION_XML = 'application/xml'; // do not localize
CONTENTTYPE_APPLICATION_XML_DTD = 'application/xml-dtd'; // do not localize
CONTENTTYPE_APPLICATION_XOP_XML = 'application/xop+xml'; // do not localize
CONTENTTYPE_APPLICATION_ZIP = 'application/zip'; // do not localize
CONTENTTYPE_APPLICATION_GZIP = 'application/gzip'; // do not localize
// Type Text
CONTENTTYPE_TEXT_CMD = 'text/cmd'; // do not localize
CONTENTTYPE_TEXT_CSS = 'text/css'; // do not localize
CONTENTTYPE_TEXT_CSV = 'text/csv'; // do not localize
CONTENTTYPE_TEXT_HTML = 'text/html'; // do not localize
CONTENTTYPE_TEXT_JAVASCRIPT = 'text/javascript'; // do not localize
CONTENTTYPE_TEXT_PLAIN = 'text/plain'; // do not localize
CONTENTTYPE_TEXT_VCARD = 'text/vcard'; // do not localize
CONTENTTYPE_TEXT_XML = 'text/xml'; // do not localize
// Type Audio
CONTENTTYPE_AUDIO_BASIC = 'audio/basic'; // do not localize
CONTENTTYPE_AUDIO_L24 = 'audio/L24'; // do not localize
CONTENTTYPE_AUDIO_MP4 = 'audio/mp4'; // do not localize
CONTENTTYPE_AUDIO_MPEG = 'audio/mpeg'; // do not localize
CONTENTTYPE_AUDIO_OGG = 'audio/ogg'; // do not localize
CONTENTTYPE_AUDIO_VORBIS = 'audio/vorbis'; // do not localize
CONTENTTYPE_AUDIO_VND_RN_REALAUDIO = 'audio/vnd.rn-realaudio'; // do not localize
CONTENTTYPE_AUDIO_VND_WAVE = 'audio/vnd.wave'; // do not localize
CONTENTTYPE_AUDIO_WEBM = 'audio/webm'; // do not localize
// Type Image
CONTENTTYPE_IMAGE_GIF = 'image/gif'; // do not localize
CONTENTTYPE_IMAGE_JPEG = 'image/jpeg'; // do not localize
CONTENTTYPE_IMAGE_PJPEG = 'image/pjpeg'; // do not localize
CONTENTTYPE_IMAGE_PNG = 'image/png'; // do not localize
CONTENTTYPE_IMAGE_SVG_XML = 'image/svg+xml'; // do not localize
CONTENTTYPE_IMAGE_TIFF = 'image/tiff'; // do not localize
// Type Message
CONTENTTYPE_MESSAGE_HTTP = 'message/http'; // do not localize
CONTENTTYPE_MESSAGE_IMDN_XML = 'message/imdn+xml'; // do not localize
CONTENTTYPE_MESSAGE_PARTIAL = 'message/partial'; // do not localize
CONTENTTYPE_MESSAGE_RFC822 = 'message/rfc822'; // do not localize
// Type Model (3D Models)
CONTENTTYPE_MODEL_EXAMPLE = 'model/example'; // do not localize
CONTENTTYPE_MODEL_IGES = 'model/iges'; // do not localize
CONTENTTYPE_MODEL_MESH = 'model/mesh'; // do not localize
CONTENTTYPE_MODEL_VRML = 'model/vrml'; // do not localize
CONTENTTYPE_MODEL_X3D_BINARY = 'model/x3d+binary'; // do not localize
CONTENTTYPE_MODEL_X3D_VRML = 'model/x3d+vrml'; // do not localize
CONTENTTYPE_MODEL_X3D_XML = 'model/x3d+xml'; // do not localize
// Type Multipart
CONTENTTYPE_MULTIPART_MIXED = 'multipart/mixed'; // do not localize
CONTENTTYPE_MULTIPART_ALTERNATIVE = 'multipart/alternative'; // do not localize
CONTENTTYPE_MULTIPART_RELATED = 'multipart/related'; // do not localize
CONTENTTYPE_MULTIPART_FORM_DATA = 'multipart/form-data'; // do not localize
CONTENTTYPE_MULTIPART_SIGNED = 'multipart/signed'; // do not localize
CONTENTTYPE_MULTIPART_ENCRYPTED = 'multipart/encrypted'; // do not localize
// Type Video
CONTENTTYPE_VIDEO_MPEG = 'video/mpeg'; // do not localize
CONTENTTYPE_VIDEO_MP4 = 'video/mp4'; // do not localize
CONTENTTYPE_VIDEO_OGG = 'video/ogg'; // do not localize
CONTENTTYPE_VIDEO_QUICKTIME = 'video/quicktime'; // do not localize
CONTENTTYPE_VIDEO_WEBM = 'video/webm'; // do not localize
CONTENTTYPE_VIDEO_X_MATROSKA = 'video/x-matroska'; // do not localize
CONTENTTYPE_VIDEO_X_MS_WMV = 'video/x-ms-wmv'; // do not localize
CONTENTTYPE_VIDEO_X_FLV = 'video/x-flv'; // do not localize
// Type Application - Vendor Specific
CONTENTTYPE_APPLICATION_VND_OASIS_OPENDOCUMENT_TEXT = 'application/vnd.oasis.opendocument.text'; // do not localize
CONTENTTYPE_APPLICATION_VND_OASIS_OPENDOCUMENT_SPREADSHEET = 'application/vnd.oasis.opendocument.spreadsheet';
// do not localize
CONTENTTYPE_APPLICATION_VND_OASIS_OPENDOCUMENT_PRESENTATION = 'application/vnd.oasis.opendocument.presentation';
// do not localize
CONTENTTYPE_APPLICATION_VND_OASIS_OPENDOCUMENT_GRAPHICS = 'application/vnd.oasis.opendocument.graphics';
// do not localize
CONTENTTYPE_APPLICATION_VND_MS_EXCEL = 'application/vnd.ms-excel'; // do not localize
CONTENTTYPE_APPLICATION_VND_OPENXMLFORMATS_OFFICEDOCUMENT_SPREADSHEETML_SHEET =
'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet'; // do not localize
CONTENTTYPE_APPLICATION_VND_MS_POWERPOINT = 'application/vnd.ms-powerpoint'; // do not localize
CONTENTTYPE_APPLICATION_VND_OPENXMLFORMATS_OFFICEDOCUMENT_PRESENTATIONML_PRESENTATION =
'application/vnd.openxmlformats-officedocument.presentationml.presentation'; // do not localize
CONTENTTYPE_APPLICATION_VND_OPENXMLFORMATS_OFFICEDOCUMENT_WORDPROCESSINGML_DOCUMENT =
'application/vnd.openxmlformats-officedocument.wordprocessingml.document'; // do not localize
CONTENTTYPE_APPLICATION_VND_MOZILLA_XUL_XML = 'application/vnd.mozilla.xul+xml'; // do not localize
CONTENTTYPE_APPLICATION_VND_GOOGLE_EARTH_KML_XML = 'application/vnd.google-earth.kml+xml'; // do not localize
CONTENTTYPE_APPLICATION_VND_GOOGLE_EARTH_KMZ = 'application/vnd.google-earth.kmz'; // do not localize
CONTENTTYPE_APPLICATION_VND_DART = 'application/vnd.dart'; // do not localize
CONTENTTYPE_APPLICATION_VND_ANDROID_PACKAGE_ARCHIVE = 'application/vnd.android.package-archive'; // do not localize
// Type X (RFC 6648)
CONTENTTYPE_APPLICATION_X_DEB = 'application/x-deb'; // do not localize
CONTENTTYPE_APPLICATION_X_DVI = 'application/x-dvi'; // do not localize
CONTENTTYPE_APPLICATION_X_FONT_TTF = 'application/x-font-ttf'; // do not localize
CONTENTTYPE_APPLICATION_X_JAVASCRIPT = 'application/x-javascript'; // do not localize
CONTENTTYPE_APPLICATION_X_LATEX = 'application/x-latex'; // do not localize
CONTENTTYPE_APPLICATION_X_MPEGURL = 'application/x-mpegURL'; // do not localize
CONTENTTYPE_APPLICATION_X_RAR_COMPRESSED = 'application/x-rar-compressed'; // do not localize
CONTENTTYPE_APPLICATION_X_SHOCKWAVE_FLASH = 'application/x-shockwave-flash'; // do not localize
CONTENTTYPE_APPLICATION_X_STUFFIT = 'application/x-stuffit'; // do not localize
CONTENTTYPE_APPLICATION_X_TAR = 'application/x-tar'; // do not localize
CONTENTTYPE_APPLICATION_X_WWW_FORM_URLENCODED = 'application/x-www-form-urlencoded'; // do not localize
CONTENTTYPE_APPLICATION_X_XPINSTALL = 'application/x-xpinstall'; // do not localize
CONTENTTYPE_AUDIO_X_AAC = 'audio/x-aac'; // do not localize
CONTENTTYPE_AUDIO_X_CAF = 'audio/x-caf'; // do not localize
CONTENTTYPE_IMAGE_X_XCF = 'image/x-xcf'; // do not localize
CONTENTTYPE_TEXT_X_GWT_RPC = 'text/x-gwt-rpc'; // do not localize
CONTENTTYPE_TEXT_X_JQUERY_TMPL = 'text/x-jquery-tmpl'; // do not localize
CONTENTTYPE_TEXT_X_MARKDOWN = 'text/x-markdown'; // do not localize
// Type PKCS (Cryptography)
CONTENTTYPE_APPLICATION_X_PKCS12 = 'application/x-pkcs12'; // do not localize
CONTENTTYPE_APPLICATION_X_PKCS7_CERTIFICATES = 'application/x-pkcs7-certificates'; // do not localize
CONTENTTYPE_APPLICATION_X_PKCS7_CERTREQRESP = 'application/x-pkcs7-certreqresp'; // do not localize
CONTENTTYPE_APPLICATION_X_PKCS7_MIME = 'application/x-pkcs7-mime'; // do not localize
CONTENTTYPE_APPLICATION_X_PKCS7_SIGNATURE = 'application/x-pkcs7-signature'; // do not localize
// Type Application - Embarcadero Specific
CONTENTTYPE_APPLICATION_VND_EMBARCADERO_FIREDAC_JSON = 'application/vnd.embarcadero.firedac+json'; // do not localize
function ContentTypeToString(AContentType: TRESTContentType): string;
function ContentTypeFromString(const AContentType: string): TRESTContentType;
function IsTextualContentType(AContentType: TRESTContentType) : boolean; overload;
function IsTextualContentType(const AContentType: string) : boolean; overload;
2.3、
TRESTRequestMethod枚举
rmPOST
rmPUT
rmGET
rmDELETE
rmPATCH
--->
const sRequestDefaultAccept = CONTENTTYPE_APPLICATION_JSON + ', ' +
CONTENTTYPE_TEXT_PLAIN + '; q=0.9, ' + CONTENTTYPE_TEXT_HTML + ';q=0.8,';
// UTF-8 is prefered, any other is good, but marked down: sRequestDefaultAcceptCharset = 'utf-8, *;q=0.8'; sDefaultFallbackCharSetEncoding = 'utf-8'; sDefaultUserAgent = 'Embarcadero RESTClient/' + RESTCLIENT_VERSION; sBody = 'body'; sFile = 'file';
2.4、
RESTRequest.ResetToDefaults;
Method := DefaultRESTRequestMethod;
Resource := '';
ResourceSuffix := '';
Timeout := 30000; // Some servers may be slow. Esp if they just recycled and need to start up on their first request
Accept := sRequestDefaultAccept;
AcceptCharset := sRequestDefaultAcceptCharset;
HandleRedirects := True;
FExecutionPerformance.Clear;
FURLAlreadyEncoded := False;
FParams.Clear;
FTransientParams.Clear;
FBody.ClearBody;
if FClient <> nil then
FClient.ContentType := '';
if FResponse <> nil then
FResponse.ResetToDefaults;
// we intentionally do not reset "FAutoCreateParams"
var DefaultRESTRequestMethod: TRESTRequestMethod = TRESTRequestMethod.rmGET;
function RESTRequestMethodToString(const AMethod: TRESTRequestMethod): string;
Executes a request asynchronously, i.e. run it in its own thread. There is no automatic serialization op
property access though, which means that while the execution thread runs, properties of all involved
TCustomRESTClient and TCustomRESTRequest instances should not be touched from other threads (including the main thread)
Using ExecuteAsync is strongly recommended on mobile platforms. iOS (and likely Android) will
terminate an application if it considers the main thread to be unresponsive, which would be the case if
there is a running request which takes more than a second or two to return.
执行异步请求,即在自己的线程中运行它。没有自动序列化op
属性访问,这意味着在执行线程运行时,所有相关的属性
TCustomRESTClient和TCustomRESTRequest实例不应该触及从其他线程(包括主线程)
移动平台上使用ExecuteAsync是强烈推荐。iOS(和可能Android)
终止应用程序如果认为主线程是反应迟钝,如果这将是如此
有一个请求,需要超过一两秒钟返回。
摘要说明:
The idea behind this is that the UI runs in the main thread and mobile devices should respond to user
interaction basically immediately. Sluggish behaviour (caused by blocking the main thread) is considered
unacceptable on these small devices.
背后的想法是,用户界面运行在主线程和移动设备应该响应用户
互动基本上立即。缓慢的行为(阻塞主线程所致)
这些小设备上不可接受。
参数: name=ARequest
The request to be executed 要执行的请求
:参数结束
参数: name=ACompletionHandler
An anonymous method that will be run after the execution completed
execute执行完成后的1个一个匿名方法
参数: name=ASynchronized
Specifies if ACompletioHandler will be run in the main thread's (True) or execution thread's (False) context
如果指定了ACompletioHandler,它将运行在主线程(True),否则它在执行线程的上下文运行(False)
参数: name=AFreeThread
If True, then the execution thread will be freed after it completed
如果True,那么运行完成后执行线程将被释放
参数: name=ACompletionHandlerWithError
An anonymous method that will be run if an exception is raised during execution
在执行期间如果抛出异常,这个一个匿名方法将被执行
返回值:
Returns a reference to the execution thread. Should only be used if AFreeThread=False,
as other wise the reference may get invalid unexpectedly.
返回对执行线程的引用。只用于参数AFreeThread = False,否则
返回的这个引用可能会意外的无效。
请发表评论