{"id":169,"date":"2017-12-07T19:48:22","date_gmt":"2017-12-07T11:48:22","guid":{"rendered":"http:\/\/www.ponybai.com\/?p=169"},"modified":"2017-12-07T19:48:22","modified_gmt":"2017-12-07T11:48:22","slug":"apex-rest%e5%a4%96%e9%83%a8%e8%b0%83%e7%94%a8","status":"publish","type":"post","link":"http:\/\/www.ponybai.com\/?p=169","title":{"rendered":"Apex REST\u5916\u90e8\u8c03\u7528"},"content":{"rendered":"<div class=\"nested0\">\n<h2 id=\"Tdxn4tBK-heading1\" class=\"helpHead2\">\u5b66\u4e60\u76ee\u6807<\/h2>\n<div class=\"body\">\n<div id=\"p2\" class=\"p\">\n<p>\u5b8c\u6210\u540e\uff0c\u60a8\u5c06\u80fd\u591f\uff1a<\/p>\n<ul class=\"ul bulletList\">\n<li class=\"li\">\u6267\u884c\u5916\u547c\u4ee5\u63a5\u6536\u6765\u81ea\u5916\u90e8\u670d\u52a1\u7684\u6570\u636e\u3002<\/li>\n<li class=\"li\">\u6267\u884c\u5916\u547c\u5c06\u6570\u636e\u53d1\u9001\u5230\u5916\u90e8\u670d\u52a1\u3002<\/li>\n<li class=\"li\">\u4f7f\u7528\u6a21\u62df\u6807\u6ce8\u6d4b\u8bd5\u5916\u547c\u3002<\/li>\n<\/ul>\n<\/div>\n<\/div>\n<\/div>\n<div id=\"apex_integration_rest_http_basics\" class=\"topic concept nested0\" lang=\"en-us\" xml:lang=\"en-us\">\n<h2 id=\"Tdxn4tBK-heading2\" class=\"helpHead2\"><span id=\"topic-title\" class=\"ph\">HTTP\u548c\u5916\u547c\u57fa\u7840<\/span><\/h2>\n<div class=\"body conbody\">\n<div class=\"shortdesc\">REST\u5916\u547c\u57fa\u4e8eHTTP\u3002\u8981\u4e86\u89e3\u5916\u547c\u5982\u4f55\u5de5\u4f5c\uff0c\u4e86\u89e3\u4e00\u4e9b\u6709\u5173HTTP\u7684\u5185\u5bb9\u5f88\u6709\u5e2e\u52a9\u3002\u6bcf\u4e2a\u5916\u547c\u8bf7\u6c42\u90fd\u4e0eHTTP\u65b9\u6cd5\u548c\u7aef\u70b9\u76f8\u5173\u8054\u3002 HTTP\u65b9\u6cd5\u6307\u793a\u9700\u8981\u4ec0\u4e48\u7c7b\u578b\u7684\u52a8\u4f5c\u3002<\/div>\n<div id=\"fig_g24_lxb_b5\" class=\"fig fignone\">\n<div class=\"imagecenter\"><span class=\"image image-block\"><img decoding=\"async\" id=\"image_h24_lxb_b5\" class=\"image image-block\" src=\"https:\/\/res.cloudinary.com\/hy4kyit2a\/image\/upload\/doc\/trailhead\/en-us9e44c283a52e2f5ac41ea9d332799104.png\" alt=\"Apex callouts to an external service\" \/><\/span><\/div>\n<\/div>\n<p class=\"p\">\u6700\u7b80\u5355\u7684\u8bf7\u6c42\u662f\u4e00\u4e2aGET\u8bf7\u6c42\uff08GET\u662f\u4e00\u4e2aHTTP\u65b9\u6cd5\uff09\u3002 GET\u8bf7\u6c42\u610f\u5473\u7740\u53d1\u9001\u8005\u60f3\u8981\u4ece\u670d\u52a1\u5668\u83b7\u53d6\u5173\u4e8e\u8d44\u6e90\u7684\u4fe1\u606f\u3002\u5f53\u670d\u52a1\u5668\u63a5\u6536\u5e76\u5904\u7406\u6b64\u8bf7\u6c42\u65f6\uff0c\u5b83\u5c06\u8bf7\u6c42\u4fe1\u606f\u8fd4\u56de\u7ed9\u6536\u4ef6\u4eba\u3002 GET\u8bf7\u6c42\u4e0e\u5bfc\u822a\u5230\u6d4f\u89c8\u5668\u4e2d\u7684\u5730\u5740\u76f8\u4f3c\u3002\u5f53\u60a8\u8bbf\u95ee\u7f51\u9875\u65f6\uff0c\u6d4f\u89c8\u5668\u4f1a\u5728\u5e55\u540e\u6267\u884cGET\u8bf7\u6c42\u3002\u5728\u6d4f\u89c8\u5668\u4e2d\uff0c\u5bfc\u822a\u7684\u7ed3\u679c\u662f\u663e\u793a\u7684\u65b0HTML\u9875\u9762\u3002\u7528\u5916\u547c\uff0c\u7ed3\u679c\u662f\u54cd\u5e94\u5bf9\u8c61\u3002<\/p>\n<p class=\"p\">\u4e3a\u4e86\u8bf4\u660eGET\u8bf7\u6c42\u7684\u5de5\u4f5c\u65b9\u5f0f\uff0c\u6253\u5f00\u6d4f\u89c8\u5668\u5e76\u5bfc\u822a\u5230\u4ee5\u4e0bURI:\u00a0<a class=\"xref\" title=\"HTML (New Window)\" href=\"https:\/\/th-apex-http-callout.herokuapp.com\/animals\" target=\"_blank\" rel=\"noopener\">https:\/\/th-apex-http-callout.herokuapp.com\/animals<\/a>.\u60a8\u7684\u6d4f\u89c8\u5668\u4ee5\u5947\u602a\u7684\u683c\u5f0f\u663e\u793a\u52a8\u7269\u5217\u8868\uff0c\u56e0\u4e3a\u670d\u52a1\u4ee5JSON\u683c\u5f0f\u8fd4\u56de\u54cd\u5e94\u3002\u6709\u65f6GET\u54cd\u5e94\u4e5f\u662f\u7528XML\u683c\u5f0f\u5316\u7684\u3002<\/p>\n<p class=\"p\">\u4ee5\u4e0b\u662f\u5e38\u7528HTTP\u65b9\u6cd5\u7684\u8bf4\u660e\u3002<\/p>\n<div class=\"data colSort\">\n<p>\u88681.\u4e00\u4e9b\u5e38\u7528\u7684HTTP\u65b9\u6cd5<\/p>\n<table class=\"featureTable sort_table\" summary=\"\">\n<thead class=\"thead sorted\" align=\"left\">\n<tr>\n<th id=\"d26221e79\" class=\"featureTableHeader \">HTTP\u65b9\u6cd5<\/th>\n<th id=\"d26221e82\" class=\"featureTableHeader \">\u63cf\u8ff0<\/th>\n<\/tr>\n<\/thead>\n<tbody class=\"tbody\">\n<tr>\n<td class=\"entry\" headers=\"d26221e79\" data-title=\"HTTP Method\">GET<\/td>\n<td class=\"entry\" headers=\"d26221e82\" data-title=\"Description\">\u68c0\u7d22\u7531URL\u6807\u8bc6\u7684\u6570\u636e<\/td>\n<\/tr>\n<tr>\n<td class=\"entry\" headers=\"d26221e79\" data-title=\"HTTP Method\">POST<\/td>\n<td class=\"entry\" headers=\"d26221e82\" data-title=\"Description\">\u521b\u5efa\u8d44\u6e90\u6216\u5c06\u6570\u636e\u53d1\u5e03\u5230\u670d\u52a1\u5668\u3002<\/td>\n<\/tr>\n<tr>\n<td class=\"entry\" headers=\"d26221e79\" data-title=\"HTTP Method\">DELETE<\/td>\n<td class=\"entry\" headers=\"d26221e82\" data-title=\"Description\">\u5220\u9664\u7531URL\u6807\u8bc6\u7684\u8d44\u6e90\u3002<\/td>\n<\/tr>\n<tr>\n<td class=\"entry\" headers=\"d26221e79\" data-title=\"HTTP Method\">PUT<\/td>\n<td class=\"entry\" headers=\"d26221e82\" data-title=\"Description\">\u521b\u5efa\u6216\u66ff\u6362\u8bf7\u6c42\u6b63\u6587\u4e2d\u53d1\u9001\u7684\u8d44\u6e90\u3002<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<\/div>\n<p class=\"p\">\u5982\u679c\u60a8\u6709\u7a7a\u95f2\u65f6\u95f4\uff0c\u8bf7\u5728\u53c2\u8003\u8d44\u6599\u90e8\u5206\u6d4f\u89c8\u6240\u6709HTTP\u65b9\u6cd5\u7684\u8be6\u5c3d\u5217\u8868\u3002<\/p>\n<p class=\"p\">\u9664\u4e86HTTP\u65b9\u6cd5\u4e4b\u5916\uff0c\u6bcf\u4e2a\u8bf7\u6c42\u90fd\u4f1a\u8bbe\u7f6e\u4e00\u4e2aURI\uff0c\u8fd9\u662f\u670d\u52a1\u6240\u5728\u7684\u7aef\u70b9\u5730\u5740\u3002\u4f8b\u5982\uff0c\u4e00\u4e2a\u7aef\u70b9\u53ef\u4ee5\u662f <span class=\"ph filepath\">http:\/\/www.example.com\/api\/resource<\/span>.\u5728 \u201cHTTP and Callout Basics\u201d \u5355\u5143\u4e2d\u7684\u793a\u4f8b\u4e2d\uff0c\u7aef\u70b9\u662f<span class=\"ph filepath\">https:\/\/th-apex-http-callout.herokuapp.com\/animals<\/span>.<\/p>\n<p class=\"p\">\u5f53\u670d\u52a1\u5668\u5904\u7406\u8bf7\u6c42\u65f6\uff0c\u5b83\u5728\u54cd\u5e94\u4e2d\u53d1\u9001\u4e00\u4e2a\u72b6\u6001\u7801\u3002\u72b6\u6001\u7801\u6307\u793a\u8bf7\u6c42\u662f\u5426\u6210\u529f\u5904\u7406\u6216\u662f\u5426\u9047\u5230\u9519\u8bef\u3002\u5982\u679c\u8bf7\u6c42\u6210\u529f\uff0c\u670d\u52a1\u5668\u4f1a\u53d1\u9001\u4e00\u4e2a200\u7684\u72b6\u6001\u7801\u3002\u60a8\u53ef\u80fd\u5df2\u7ecf\u770b\u5230\u4e00\u4e9b\u5176\u4ed6\u7684\u72b6\u6001\u7801\uff0c\u4f8b\u5982404\u6ca1\u6709\u627e\u5230\u6587\u4ef6\uff0c500\u6ca1\u6709\u627e\u5230\u5185\u90e8\u670d\u52a1\u5668\u9519\u8bef\u3002<\/p>\n<p class=\"p\">\u5982\u679c\u5728\u6d4f\u89c8HTTP\u65b9\u6cd5\u5217\u8868\u540e\u4ecd\u7136\u6709\u7a7a\u95f2\u65f6\u95f4\uff0c\u8bf7\u67e5\u770b\u53c2\u8003\u8d44\u6599\u90e8\u5206\u7684\u6240\u6709\u54cd\u5e94\u72b6\u6001\u4ee3\u7801\u5217\u8868\u3002\u5982\u679c\u4f60\u665a\u4e0a\u7761\u5f97\u5f88\u56f0\u96be\uff0c\u8fd9\u4e24\u4e2a\u8d44\u6e90\u53ef\u4ee5\u5e2e\u52a9\u4f60\u3002<\/p>\n<div class=\"box message info\"><\/div>\n<\/div>\n<\/div>\n<div id=\"apex_integration_rest_get_example\" class=\"topic task nested0\" lang=\"en-us\" xml:lang=\"en-us\">\n<h2 id=\"Tdxn4tBK-heading4\" class=\"helpHead2\"><span id=\"topic-title\" class=\"ph\">\u4ece\u670d\u52a1\u83b7\u53d6\u6570\u636e<\/span><\/h2>\n<div class=\"body taskbody\">\n<div class=\"shortdesc\">\u73b0\u5728\u662f\u65f6\u5019\u628a\u4f60\u7684\u65b0HTTP\u77e5\u8bc6\u7528\u4e8e\u4e00\u4e9bApex\u6807\u6ce8\u3002\u672c\u793a\u4f8b\u5411Web\u670d\u52a1\u53d1\u9001GET\u8bf7\u6c42\u4ee5\u83b7\u53d6\u6797\u5730\u751f\u7269\u5217\u8868\u3002\u8be5\u670d\u52a1\u4ee5JSON\u683c\u5f0f\u53d1\u9001\u54cd\u5e94\u3002 JSON\u672c\u8d28\u4e0a\u662f\u4e00\u4e2a\u5b57\u7b26\u4e32\uff0c\u6240\u4ee5\u5185\u7f6e\u7684JSONParser\u7c7b\u5c06\u5b83\u8f6c\u6362\u4e3a\u4e00\u4e2a\u5bf9\u8c61\u3002\u7136\u540e\uff0c\u6211\u4eec\u53ef\u4ee5\u4f7f\u7528\u8be5\u5bf9\u8c61\u5c06\u6bcf\u4e2a\u52a8\u7269\u7684\u540d\u79f0\u5199\u5165\u8c03\u8bd5\u65e5\u5fd7\u3002<br \/>\n\u5728\u672c\u673a\u8fd0\u884c\u793a\u4f8b\u4e4b\u524d\uff0c\u60a8\u9700\u8981\u4f7f\u7528\u201c\u6388\u6743\u7aef\u70b9\u5730\u5740\u201d\u90e8\u5206\u4e2d\u7684\u6b65\u9aa4\u6765\u6388\u6743\u6807\u6ce8\u7684\u7aef\u70b9URL ,\u00a0<span class=\"ph filepath\">https:\/\/th-apex-http-callout.herokuapp.com<\/span>, \u4f7f\u7528\u201c\u6388\u6743\u7aef\u70b9\u5730\u5740\u201d\u90e8\u5206\u7684\u6b65\u9aa4\u3002<\/div>\n<ol class=\"ol steps enumList\">\n<li class=\"li step\"><span class=\"ph cmd\">\u4ece\u8bbe\u7f6e\u6863\uff08\u6253\u5f00\u8bbe\u5907\u9f7f\u8f6e\u56fe\u6807\uff09\u6253\u5f00\u5f00\u53d1\u8005\u63a7\u5236\u53f0\u3002 (<img decoding=\"async\" class=\"image\" src=\"https:\/\/res.cloudinary.com\/hy4kyit2a\/image\/upload\/doc\/trailhead\/en-usd53c37ae7a304569f11b01c79f4df2ee.png\" alt=\"Setup gear icon\" \/>).<\/span><\/li>\n<li class=\"li step\"><span class=\"ph cmd\">\u5728\u5f00\u53d1\u8005\u63a7\u5236\u53f0\u4e2d\uff0c\u9009\u62e9 <span class=\"ph menucascade\"><strong class=\"ph uicontrol\">Debug<\/strong>\u00a0|\u00a0<strong class=\"ph uicontrol\">Open Execute Anonymous Window<\/strong><\/span>.<\/span><\/li>\n<li class=\"li step\">\u5220\u9664\u73b0\u6709\u7684\u4ee3\u7801\u5e76\u63d2\u5165\u4e0b\u9762\u7684\u4ee3\u7801\u7247\u6bb5<br \/>\nHttp http = new Http();<br \/>\nHttpRequest request = new HttpRequest();<br \/>\nrequest.setEndpoint(&#8216;https:\/\/th-apex-http-callout.herokuapp.com\/animals&#8217;);<br \/>\nrequest.setMethod(&#8216;GET&#8217;);<br \/>\nHttpResponse response = http.send(request);<br \/>\n\/\/ \u5982\u679c\u8bf7\u6c42\u6210\u529f\uff0c\u5219\u89e3\u6790JSON\u54cd\u5e94\u3002<br \/>\nif (response.getStatusCode() == 200) {<br \/>\n\/\/ \u5c06JSON\u5b57\u7b26\u4e32\u53cd\u5e8f\u5217\u5316\u4e3a\u539f\u59cb\u6570\u636e\u7c7b\u578b\u7684\u96c6\u5408\u3002<br \/>\nMap&lt;String, Object&gt; results = (Map&lt;String, Object&gt;) JSON.deserializeUntyped(response.getBody());<br \/>\n\/\/ \u201c\u52a8\u7269\u201d\u952e\u4e2d\u7684\u503c\u4f5c\u4e3a\u5217\u8868\u8fdb\u884c\u6295\u5c04<br \/>\nList&lt;Object&gt; animals = (List&lt;Object&gt;) results.get(&#8216;animals&#8217;);<br \/>\nSystem.debug(&#8216;Received the following animals:&#8217;);<br \/>\nfor (Object animal: animals) {<br \/>\nSystem.debug(animal);<br \/>\n}<br \/>\n}<\/li>\n<li class=\"li step\"><span class=\"ph cmd\">\u9009\u62e9\u00a0<strong class=\"ph uicontrol\">Open Log<\/strong>, \u7136\u540e\u5355\u51fb<strong class=\"ph uicontrol\">Execute<\/strong>.<\/span><\/li>\n<li class=\"li step\"><span class=\"ph cmd\">\u8c03\u8bd5\u65e5\u5fd7\u6253\u5f00\u540e\uff0c\u9009\u62e9 <strong class=\"ph uicontrol\">Debug Only<\/strong> \u67e5\u770bSystem.debug\u8bed\u53e5\u7684\u8f93\u51fa\u3002<\/span>\n<div class=\"itemgroup stepresult\">\u663e\u793a\u52a8\u7269\u7684\u540d\u5b57\u3002<\/div>\n<\/li>\n<\/ol>\n<div class=\"section postreq\">\n<p class=\"p\">\u6211\u4eec\u4f8b\u5b50\u4e2d\u7684JSON\u76f8\u5f53\u7b80\u5355\u5e76\u4e14\u6613\u4e8e\u89e3\u6790\u3002\u5bf9\u4e8e\u66f4\u590d\u6742\u7684JSON\u7ed3\u6784\uff0c\u53ef\u4ee5\u4f7f\u7528JSON2Apex\u3002\u8be5\u5de5\u5177\u751f\u6210\u7528\u4e8e\u89e3\u6790JSON\u7ed3\u6784\u7684\u5f3a\u7c7b\u578b\u7684Apex\u4ee3\u7801\u3002\u60a8\u53ea\u9700\u7c98\u8d34JSON\uff0c\u8be5\u5de5\u5177\u5c31\u4f1a\u4e3a\u60a8\u751f\u6210\u5fc5\u8981\u7684Apex\u4ee3\u7801\u3002\u8363\u8000\uff01<\/p>\n<\/div>\n<\/div>\n<\/div>\n<div id=\"apex_integration_rest_post_example\" class=\"topic task nested0\" lang=\"en-us\" xml:lang=\"en-us\">\n<h2 id=\"Tdxn4tBK-heading5\" class=\"helpHead2\"><span id=\"topic-title\" class=\"ph\">\u53d1\u9001\u6570\u636e\u5230\u670d\u52a1<\/span><\/h2>\n<div class=\"body taskbody\">\n<div class=\"shortdesc\">HTTP \u5916\u547c\u7684\u53e6\u4e00\u4e2a\u5e38\u89c1\u7528\u4f8b\u662f\u5c06\u6570\u636e\u53d1\u9001\u5230\u670d\u52a1\u3002\u4f8b\u5982\uff0c\u5f53\u60a8\u8d2d\u4e70\u6700\u65b0\u7684\u8d3e\u65af\u6c40\u00b7\u6bd4\u4f2f\uff08Justin Bieber\uff09\u4e13\u8f91\u6216\u8bc4\u8bba\u60a8\u6700\u559c\u6b22\u7684\u201cCat in a Shark Costume Chases a Duck While Riding a Roomba\u201d\u89c6\u9891\u65f6\uff0c\u60a8\u7684\u6d4f\u89c8\u5668\u6b63\u5728\u63d0\u4ea4POST\u8bf7\u6c42\u4ee5\u63d0\u4ea4\u6570\u636e\u3002\u6211\u4eec\u6765\u770b\u770b\u6211\u4eec\u5982\u4f55\u5728Apex\u4e2d\u53d1\u9001\u6570\u636e\u3002<br \/>\n\u672c\u793a\u4f8b\u5411Web\u670d\u52a1\u53d1\u9001POST\u8bf7\u6c42\u4ee5\u6dfb\u52a0\u52a8\u7269\u540d\u79f0\u3002\u65b0\u540d\u79f0\u4f5c\u4e3aJSON\u5b57\u7b26\u4e32\u6dfb\u52a0\u5230\u8bf7\u6c42\u6b63\u6587\u4e2d\u3002\u8bf7\u6c42Content-Type\u5934\u8bbe\u7f6e\u4e3a\u8ba9\u670d\u52a1\u77e5\u9053\u53d1\u9001\u7684\u6570\u636e\u662fJSON\u683c\u5f0f\uff0c\u4ee5\u4fbf\u5b83\u53ef\u4ee5\u9002\u5f53\u5730\u5904\u7406\u6570\u636e\u3002\u8be5\u670d\u52a1\u901a\u8fc7\u53d1\u9001\u72b6\u6001\u4ee3\u7801\u548c\u6240\u6709\u52a8\u7269\u5217\u8868\uff08\u5305\u62ec\u60a8\u6dfb\u52a0\u7684\u52a8\u7269\uff09\u4f5c\u51fa\u54cd\u5e94\u3002\u5982\u679c\u8bf7\u6c42\u5df2\u6210\u529f\u5904\u7406\uff0c\u5219\u72b6\u6001\u7801\u5c06\u8fd4\u56de201\uff0c\u56e0\u4e3a\u5df2\u521b\u5efa\u8d44\u6e90\u3002\u5982\u679c\u8fd4\u56de201\u4ee5\u5916\u7684\u4efb\u4f55\u5185\u5bb9\uff0c\u5219\u5c06\u54cd\u5e94\u53d1\u9001\u5230\u8c03\u8bd5\u65e5\u5fd7\u3002<\/div>\n<ol class=\"ol steps enumList\">\n<li class=\"li step\"><span class=\"ph cmd\">\u4ece\u8bbe\u7f6e\u6863\uff08\u6253\u5f00\u8bbe\u5907\u9f7f\u8f6e\u56fe\u6807\uff09\u6253\u5f00\u5f00\u53d1\u8005\u63a7\u5236\u53f0 (<img decoding=\"async\" class=\"image\" src=\"https:\/\/res.cloudinary.com\/hy4kyit2a\/image\/upload\/doc\/trailhead\/en-usd53c37ae7a304569f11b01c79f4df2ee.png\" alt=\"Setup gear icon\" \/>).<\/span><\/li>\n<li class=\"li step\"><span class=\"ph cmd\">\u5728\u5f00\u53d1\u8005\u63a7\u5236\u53f0\u4e2d\uff0c\u9009\u62e9\u00a0<span class=\"ph menucascade\"><strong class=\"ph uicontrol\">Debug<\/strong>\u00a0|\u00a0<strong class=\"ph uicontrol\">Open Execute Anonymous Window<\/strong><\/span>.<\/span><\/li>\n<li class=\"li step\">\u5220\u9664\u4efb\u4f55\u73b0\u6709\u7684\u4ee3\u7801\u5e76\u63d2\u5165\u4ee5\u4e0b\u7247\u6bb5\u3002\n<div class=\"itemgroup info\">\n<div class=\"codeblock\">\n<div id=\"highlighter_637660\" class=\"syntaxhighlighter \">\n<div class=\"bar \">\n<div class=\"toolbar\">Http http = new Http();<br \/>\nHttpRequest request = new HttpRequest();<br \/>\nrequest.setEndpoint(&#8216;https:\/\/th-apex-http-callout.herokuapp.com\/animals&#8217;);<br \/>\nrequest.setMethod(&#8216;POST&#8217;);<br \/>\nrequest.setHeader(&#8216;Content-Type&#8217;, &#8216;application\/json;charset=UTF-8&#8217;);<br \/>\n\/\/ \u5c06\u4e3b\u4f53\u8bbe\u7f6e\u4e3aJSON\u5bf9\u8c61<br \/>\nrequest.setBody(&#8216;{&#8220;name&#8221;:&#8221;mighty moose&#8221;}&#8217;);<br \/>\nHttpResponse response = http.send(request);<br \/>\n\/\/ \u89e3\u6790JSON\u54cd\u5e94<br \/>\nif (response.getStatusCode() != 201) {<br \/>\nSystem.debug(&#8216;\u8fd4\u56de\u7684\u72b6\u6001\u4ee3\u7801\u4e0d\u662f\u9884\u671f\u7684\uff1a &#8216; +<br \/>\nresponse.getStatusCode() + &#8216; &#8216; + response.getStatus());<br \/>\n} else {<br \/>\nSystem.debug(response.getBody());<br \/>\n}<\/p>\n<div class=\"item copyToClipboard\"><\/div>\n<\/div>\n<\/div>\n<div class=\"lines\"><\/div>\n<\/div>\n<\/div>\n<\/div>\n<\/li>\n<li class=\"li step\"><span class=\"ph cmd\">\u9009\u62e9\u6253\u5f00\u00a0<strong class=\"ph uicontrol\">Open Log<\/strong>,\u00a0\u7136\u540e\u5355\u51fb <strong class=\"ph uicontrol\">Execute<\/strong>.<\/span><\/li>\n<li class=\"li step\"><span class=\"ph cmd\">\u8c03\u8bd5\u65e5\u5fd7\u6253\u5f00\u65f6\uff0c\u8bf7\u9009\u62e9 <strong class=\"ph uicontrol\">Debug Only<\/strong> \u67e5\u770bSystem.debug\u8bed\u53e5\u7684\u8f93\u51fa\u3002\u52a8\u7269\u5217\u8868\u4e2d\u7684\u6700\u540e\u4e00\u9879\u662f\u00a0<samp>&#8220;mighty moose&#8221;<\/samp>.<\/span><\/li>\n<\/ol>\n<\/div>\n<\/div>\n<div id=\"apex_integration_rest_testing\" class=\"topic nested0\" lang=\"en-us\" xml:lang=\"en-us\">\n<h2 id=\"Tdxn4tBK-heading6\" class=\"helpHead2\"><span id=\"topic-title\" class=\"ph\">\u6d4b\u8bd5\u5916\u547c<\/span><\/h2>\n<div class=\"body\">\n<p class=\"p\">\u5916\u547c\u6d4b\u8bd5\u6709\u597d\u6d88\u606f\u548c\u574f\u6d88\u606f\u3002\u574f\u6d88\u606f\u662fApex\u6d4b\u8bd5\u65b9\u6cd5\u4e0d\u652f\u6301\u5916\u547c\uff0c\u6267\u884c\u6807\u6ce8\u7684\u6d4b\u8bd5\u5931\u8d25\u3002\u597d\u6d88\u606f\u662f\u6d4b\u8bd5\u8fd0\u884c\u65f6\u5141\u8bb8\u4f60\u201cmock\u201d\u5916\u547c\u3002\u6a21\u62df\u6807\u6ce8\u5141\u8bb8\u60a8\u6307\u5b9a\u5728\u6d4b\u8bd5\u4e2d\u8fd4\u56de\u7684\u54cd\u5e94\uff0c\u800c\u4e0d\u662f\u5b9e\u9645\u8c03\u7528Web\u670d\u52a1\u3002\u4f60\u5b9e\u9645\u4e0a\u5728\u544a\u8bc9\u8fd0\u884c\u65f6\uff0c\u201c\u6211\u77e5\u9053\u8fd9\u4e2aweb\u670d\u52a1\u5c06\u4f1a\u8fd4\u56de\u4ec0\u4e48\uff0c\u6240\u4ee5\u4e0d\u8981\u5728\u6d4b\u8bd5\u8fc7\u7a0b\u4e2d\u8c03\u7528\u5b83\uff0c\u800c\u662f\u8fd4\u56de\u8fd9\u4e2a\u6570\u636e\u3002\u201d\u5728\u4f60\u7684\u6d4b\u8bd5\u4e2d\u4f7f\u7528\u6a21\u62df\u6807\u6ce8\u6709\u52a9\u4e8e\u786e\u4fdd\u4f60\u83b7\u5f97\u8db3\u591f\u7684\u4ee3\u7801\u8986\u76d6\u7387\uff0c\u4ee3\u7801\u7531\u4e8e\u6807\u6ce8\u800c\u88ab\u8df3\u8fc7\u3002<\/p>\n<div class=\"section\">\n<h3 id=\"Tdxn4tBK-heading7\" class=\"helpHead3\">\u5148\u51b3\u6761\u4ef6<\/h3>\n<p class=\"p\">\u5728\u7f16\u5199\u6d4b\u8bd5\u4e4b\u524d\uff0c\u8ba9\u6211\u4eec\u521b\u5efa\u4e00\u4e2a\u7c7b\uff0c\u5176\u4e2d\u5305\u542b\u6211\u4eec\u5728\u201c\u5c06\u6570\u636e\u53d1\u9001\u5230\u670d\u52a1\u201d\u5355\u5143\u4e2d\u533f\u540d\u6267\u884c\u7684GET\u548cPOST\u8bf7\u6c42\u793a\u4f8b\u3002\u8fd9\u4e9b\u793a\u4f8b\u7a0d\u6709\u4fee\u6539\uff0c\u4ee5\u4fbf\u8bf7\u6c42\u5728\u65b9\u6cd5\u548c\u8fd4\u56de\u503c\u4e2d\uff0c\u4f46\u5b83\u4eec\u4e0e\u524d\u9762\u7684\u793a\u4f8b\u57fa\u672c\u76f8\u540c\u3002<\/p>\n<\/div>\n<ol class=\"ol enumList\">\n<li class=\"li\">\u5728\u5f00\u53d1\u8005\u63a7\u5236\u53f0\u4e2d\uff0c\u9009\u62e9\u00a0<span class=\"ph menucascade\"><strong class=\"ph uicontrol\">File<\/strong>\u00a0|\u00a0<strong class=\"ph uicontrol\">New<\/strong>\u00a0|\u00a0<strong class=\"ph uicontrol\">Apex Class<\/strong><\/span>.<\/li>\n<li class=\"li\"><kbd class=\"ph userinput\">\u5bf9\u4e8e\u8bfe\u7a0b\u540d\u79f0\uff0c\u8bf7\u8f93\u5165AnimalsCallouts<\/kbd> \u7136\u540e\u5355\u51fb<strong class=\"ph uicontrol\">OK<\/strong>.<\/li>\n<li class=\"li\">\u5c06\u81ea\u52a8\u751f\u6210\u7684\u4ee3\u7801\u66ff\u6362\u4e3a\u4ee5\u4e0b\u7c7b\u5b9a\u4e49\u3002\n<div class=\"codeblock\">\n<div id=\"highlighter_467682\" class=\"syntaxhighlighter \">\n<div class=\"bar \">\n<div class=\"toolbar\">\n<p>public class AnimalsCallouts {<\/p>\n<p>public static HttpResponse makeGetCallout() {<br \/>\nHttp http = new Http();<br \/>\nHttpRequest request = new HttpRequest();<br \/>\nrequest.setEndpoint(&#8216;https:\/\/th-apex-http-callout.herokuapp.com\/animals&#8217;);<br \/>\nrequest.setMethod(&#8216;GET&#8217;);<br \/>\nHttpResponse response = http.send(request);<br \/>\n\/\/\u5982\u679c\u8bf7\u6c42\u6210\u529f\uff0c\u5219\u89e3\u6790JSON\u54cd\u5e94\u3002<br \/>\nif (response.getStatusCode() == 200) {<br \/>\n\/\/ \u5c06JSON\u5b57\u7b26\u4e32\u53cd\u5e8f\u5217\u5316\u4e3a\u539f\u59cb\u6570\u636e\u7c7b\u578b\u7684\u96c6\u5408\u3002<br \/>\nMap&lt;String, Object&gt; results = (Map&lt;String, Object&gt;) JSON.deserializeUntyped(response.getBody());<br \/>\n\/\/ \u5c06\u201canimals\u201d\u952e\u4e2d\u7684\u503c\u4f5c\u4e3a\u5217\u8868\u8fdb\u884c\u6295\u5c04<br \/>\nList&lt;Object&gt; animals = (List&lt;Object&gt;) results.get(&#8216;animals&#8217;);<br \/>\nSystem.debug(&#8216;Received the following animals:&#8217;);<br \/>\nfor (Object animal: animals) {<br \/>\nSystem.debug(animal);<br \/>\n}<br \/>\n}<br \/>\nreturn response;<br \/>\n}<\/p>\n<p>public static HttpResponse makePostCallout() {<br \/>\nHttp http = new Http();<br \/>\nHttpRequest request = new HttpRequest();<br \/>\nrequest.setEndpoint(&#8216;https:\/\/th-apex-http-callout.herokuapp.com\/animals&#8217;);<br \/>\nrequest.setMethod(&#8216;POST&#8217;);<br \/>\nrequest.setHeader(&#8216;Content-Type&#8217;, &#8216;application\/json;charset=UTF-8&#8217;);<br \/>\nrequest.setBody(&#8216;{&#8220;name&#8221;:&#8221;mighty moose&#8221;}&#8217;);<br \/>\nHttpResponse response = http.send(request);<br \/>\n\/\/ \u89e3\u6790JSON\u54cd\u5e94<br \/>\nif (response.getStatusCode() != 201) {<br \/>\nSystem.debug(&#8216;\u9884\u671f\u4e0d\u4f1a\u8fd4\u56de\u72b6\u6001\u7801\uff1a &#8216; +<br \/>\nresponse.getStatusCode() + &#8216; &#8216; + response.getStatus());<br \/>\n} else {<br \/>\nSystem.debug(response.getBody());<br \/>\n}<br \/>\nreturn response;<br \/>\n}<\/p>\n<p>}<\/p>\n<\/div>\n<\/div>\n<div class=\"lines\"><\/div>\n<\/div>\n<\/div>\n<\/li>\n<li class=\"li\">\u6309\u4e0b<strong>\u00a0<kbd class=\"ph userinput\">CTRL+S<\/kbd><\/strong>\u00a0\u4fdd\u5b58..<\/li>\n<\/ol>\n<div class=\"section\">\n<h3 id=\"Tdxn4tBK-heading8\" class=\"helpHead3\">\u4f7f\u7528StaticResourceCalloutMock\u6d4b\u8bd5\u5916\u547c<\/h3>\n<p class=\"p\">\u8981\u6d4b\u8bd5\u60a8\u7684\u6807\u6ce8\uff0c\u8bf7\u901a\u8fc7\u5b9e\u73b0\u63a5\u53e3\u6216\u4f7f\u7528\u9759\u6001\u8d44\u6e90\u6765\u4f7f\u7528\u6a21\u62df\u6807\u6ce8\u3002\u5728\u8fd9\u4e2a\u4f8b\u5b50\u4e2d\uff0c\u6211\u4eec\u7a0d\u540e\u4f7f\u7528\u9759\u6001\u8d44\u6e90\u548c\u6a21\u62df\u63a5\u53e3\u3002\u9759\u6001\u8d44\u6e90\u5305\u542b\u8981\u8fd4\u56de\u7684\u54cd\u5e94\u4e3b\u4f53\u3002\u540c\u6837\uff0c\u4f7f\u7528\u6a21\u62df\u6807\u6ce8\u65f6\uff0c\u8bf7\u6c42\u4e0d\u4f1a\u53d1\u9001\u5230\u7aef\u70b9\u3002\u76f8\u53cd\uff0cApex\u8fd0\u884c\u65f6\u77e5\u9053\u67e5\u627e\u5728\u9759\u6001\u8d44\u6e90\u4e2d\u6307\u5b9a\u7684\u54cd\u5e94\uff0c\u5e76\u8fd4\u56de\u5b83\u3002 Test.setMock\u65b9\u6cd5\u901a\u77e5\u8fd0\u884c\u65f6\u5728\u6d4b\u8bd5\u65b9\u6cd5\u4e2d\u4f7f\u7528\u6a21\u62df\u6807\u6ce8\u3002\u8ba9\u6211\u4eec\u770b\u770b\u6a21\u62df\u6807\u6ce8\u5728\u884c\u52a8\u3002\u9996\u5148\uff0c\u6211\u4eec\u521b\u5efa\u4e00\u4e2a\u5305\u542bJSON\u683c\u5f0f\u5b57\u7b26\u4e32\u7684\u9759\u6001\u8d44\u6e90\uff0c\u7528\u4e8eGET\u8bf7\u6c42\u3002<\/p>\n<p><a name=\"ol_adq_sqn_c5\"><\/a><\/p>\n<ol id=\"ol_adq_sqn_c5\" class=\"ol enumList\">\n<li class=\"li\">\u5728\u5f00\u53d1\u8005\u63a7\u5236\u53f0\u4e2d\uff0c\u9009\u62e9\u00a0<span class=\"ph menucascade\"><strong class=\"ph uicontrol\">File<\/strong>\u00a0|\u00a0<strong class=\"ph uicontrol\">New<\/strong>\u00a0|\u00a0<strong class=\"ph uicontrol\">Static Resource<\/strong><\/span>.<\/li>\n<li class=\"li\"><kbd class=\"ph userinput\">\u5bf9\u4e8e\u540d\u79f0\uff0c\u8f93\u5165GetAnimalResource<\/kbd>.<\/li>\n<li class=\"li\">\u5bf9\u4e8eMIME\u7c7b\u578b\uff0c\u9009\u62e9<strong class=\"ph uicontrol\">text\/plain<\/strong>, \u5373\u4f7f\u4f7f\u7528JSON.<\/li>\n<li class=\"li\">\u70b9\u51fb<strong class=\"ph uicontrol\">Submit<\/strong>.<\/li>\n<li class=\"li\">\u5728\u4e3a\u8d44\u6e90\u6253\u5f00\u7684\u9009\u9879\u5361\u4e2d\uff0c\u63d2\u5165\u4ee5\u4e0b\u5185\u5bb9\u3002\u786e\u4fdd\u5b83\u5168\u90e8\u5728\u4e00\u884c\u4e0a\uff0c\u4e0d\u4f1a\u4e2d\u65ad\u5230\u4e0b\u4e00\u884c\u3002\u8fd9\u4e2a\u5185\u5bb9\u5c31\u662f\u6a21\u62df\u6807\u6ce8\u8fd4\u56de\u7684\u5185\u5bb9\u3002\u8fd9\u662f\u4e09\u4e2a\u6797\u5730\u751f\u7269\u9635\u5217\u3002\n<div class=\"codeblock\">\n<div id=\"highlighter_831328\" class=\"syntaxhighlighter \">\n<div class=\"bar\">\n<div class=\"toolbar\">{&#8220;animals&#8221;: [&#8220;pesky porcupine&#8221;, &#8220;hungry hippo&#8221;, &#8220;squeaky squirrel&#8221;]}<\/div>\n<\/div>\n<div class=\"lines\"><\/div>\n<\/div>\n<\/div>\n<\/li>\n<li class=\"li\"><kbd class=\"ph userinput\"><span style=\"font-family: 'Noto Serif', serif;\">\u70b9\u51fb<\/span>CTRL+S<\/kbd>\u4fdd\u5b58.<\/li>\n<\/ol>\n<p class=\"p\">\u60a8\u5df2\u6210\u529f\u521b\u5efa\u60a8\u7684\u9759\u6001\u8d44\u6e90\uff01\u73b0\u5728\uff0c\u8ba9\u6211\u4eec\u4e3a\u4f7f\u7528\u6b64\u8d44\u6e90\u7684\u6807\u6ce8\u6dfb\u52a0\u4e00\u4e2a\u6d4b\u8bd5\u3002<\/p>\n<ol id=\"ol_ip5_zqn_c5\" class=\"ol enumList\">\n<li class=\"li\">\u5728\u5f00\u53d1\u8005\u63a7\u5236\u53f0\u4e2d\uff0c\u9009\u62e9 <span class=\"ph menucascade\"><strong class=\"ph uicontrol\">File<\/strong>\u00a0|\u00a0<strong class=\"ph uicontrol\">New<\/strong>\u00a0|\u00a0<strong class=\"ph uicontrol\">Apex Class<\/strong><\/span>.<\/li>\n<li class=\"li\">\u5bf9\u4e8e\u7c7b\u540d\u79f0\uff0c\u8f93\u5165\u00a0<kbd class=\"ph userinput\">AnimalsCalloutsTest<\/kbd> \u7136\u540e\u5355\u51fb<strong class=\"ph uicontrol\">OK<\/strong>.<\/li>\n<li class=\"li\">\u5c06\u81ea\u52a8\u751f\u6210\u7684\u4ee3\u7801\u66ff\u6362\u4e3a\u4ee5\u4e0b\u6d4b\u8bd5\u7c7b\u5b9a\u4e49\u3002\n<div class=\"codeblock\">\n<div id=\"highlighter_526467\" class=\"syntaxhighlighter \">\n<div class=\"bar \">\n<div class=\"toolbar\">\n<div class=\"item copyToClipboard\">\n<p>@isTest<br \/>\nprivate class AnimalsCalloutsTest {<\/p>\n<p>@isTest static void testGetCallout() {<br \/>\n\/\/ \u57fa\u4e8e\u9759\u6001\u8d44\u6e90\u521b\u5efa\u6a21\u62df\u54cd\u5e94<br \/>\nStaticResourceCalloutMock mock = new StaticResourceCalloutMock();<br \/>\nmock.setStaticResource(&#8216;GetAnimalResource&#8217;);<br \/>\nmock.setStatusCode(200);<br \/>\nmock.setHeader(&#8216;Content-Type&#8217;, &#8216;application\/json;charset=UTF-8&#8217;);<br \/>\n\/\/\u00a0\u5916\u547c\u4e0e\u6a21\u62df\u54cd\u5e94\u76f8\u5173\u8054<br \/>\nTest.setMock(HttpCalloutMock.class, mock);<br \/>\n\/\/ \u8c03\u7528\u65b9\u6cd5\u6765\u6d4b\u8bd5<br \/>\nHttpResponse result = AnimalsCallouts.makeGetCallout();<br \/>\n\/\/ \u9a8c\u8bc1\u6a21\u62df\u54cd\u5e94\u4e0d\u4e3a\u7a7a<br \/>\nSystem.assertNotEquals(null,result,<br \/>\n&#8216;\u6807\u6ce8\u8fd4\u56de\u4e86\u4e00\u4e2a\u7a7a\u54cd\u5e94\u3002&#8217;);<br \/>\n\/\/ \u9a8c\u8bc1\u72b6\u6001\u7801<br \/>\nSystem.assertEquals(200,result.getStatusCode(),<br \/>\n&#8216;\u72b6\u6001\u7801\u4e0d\u662f200.&#8217;);<br \/>\n\/\/ \u9a8c\u8bc1\u5185\u5bb9\u7c7b\u578b<br \/>\nSystem.assertEquals(&#8216;application\/json;charset=UTF-8&#8217;,<br \/>\nresult.getHeader(&#8216;Content-Type&#8217;),<br \/>\n&#8216;The content type value is not expected.&#8217;);<br \/>\n\/\/ \u9a8c\u8bc1\u6570\u7ec4\u5305\u542b3\u4e2a\u9879\u76ee<br \/>\nMap&lt;String, Object&gt; results = (Map&lt;String, Object&gt;)<br \/>\nJSON.deserializeUntyped(result.getBody());<br \/>\nList&lt;Object&gt; animals = (List&lt;Object&gt;) results.get(&#8216;animals&#8217;);<br \/>\nSystem.assertEquals(3, animals.size(),<br \/>\n&#8216;\u6570\u7ec4\u53ea\u5e94\u8be5\u5305\u542b3\u4e2a\u9879\u76ee&#8217;);<br \/>\n}<\/p>\n<p>}<\/p>\n<\/div>\n<\/div>\n<\/div>\n<div class=\"lines\"><\/div>\n<\/div>\n<\/div>\n<\/li>\n<li class=\"li\"><span class=\"ph uicontrol\">\u70b9\u51fb<\/span><strong class=\"ph uicontrol\">CTRL+S<\/strong>\u00a0\u4fdd\u5b58.<\/li>\n<li class=\"li\">\u9009\u62e9\u00a0<span class=\"ph menucascade\"><strong class=\"ph uicontrol\">Test<\/strong>\u00a0|\u00a0<strong class=\"ph uicontrol\">Always Run Asynchronously<\/strong><\/span>. \u5982\u679c\u4e0d\u9009\u62e9\u201c\u59cb\u7ec8\u8fd0\u884c\u5f02\u6b65\u201d\uff0c\u5219\u6d4b\u8bd5\u8fd0\u884c\u53ea\u5305\u542b\u4e00\u4e2a\u540c\u6b65\u8fd0\u884c\u7684\u7c7b\u3002\u60a8\u53ea\u80fd\u4ece\u201c\u6d4b\u8bd5\u201d\u9009\u9879\u5361\u6253\u5f00\u65e5\u5fd7\uff0c\u4ee5\u8fdb\u884c\u540c\u6b65\u6d4b\u8bd5\u8fd0\u884c\u3002<br \/>\n\u8981\u8fd0\u884c\u6d4b\u8bd5\uff0c\u8bf7\u9009\u62e9<span class=\"ph menucascade\"><strong class=\"ph uicontrol\">Test<\/strong>\u00a0|\u00a0<strong class=\"ph uicontrol\">New Run<\/strong><\/span>.<\/li>\n<li class=\"li\">\u4eceTest Classes\u5217\u8868\u4e2d\u9009\u62e9 <strong class=\"ph uicontrol\">AnimalsCalloutsTest<\/strong>.<\/li>\n<li class=\"li\">\u70b9\u51fb<span class=\"ph menucascade\"><strong class=\"ph uicontrol\">Add Selected<\/strong>\u00a0|\u00a0<strong class=\"ph uicontrol\">Run<\/strong><\/span>.<\/li>\n<\/ol>\n<p class=\"p\">\u6d4b\u8bd5\u7ed3\u679c\u663e\u793a\u5728\u6d4b\u8bd5\u8fd0\u884cID\u4e0b\u7684\u6d4b\u8bd5\u9009\u9879\u5361\u4e2d\u3002\u6d4b\u8bd5\u6267\u884c\u5b8c\u6210\u540e\uff0c\u5c55\u5f00\u6d4b\u8bd5\u8fd0\u884c\u4ee5\u67e5\u770b\u8be6\u7ec6\u4fe1\u606f\u3002\u73b0\u5728\u5728\u201c\u4ee3\u7801\u603b\u4f53\u8986\u76d6\u7387\u201d\u7a97\u683c\u4e2d\u53cc\u51fbAnimalCallouts\uff0c\u67e5\u770b\u6d4b\u8bd5\u8986\u76d6\u4e86\u54ea\u4e9b\u884c\u3002<\/p>\n<\/div>\n<div class=\"section\">\n<h3 id=\"Tdxn4tBK-heading9\" class=\"helpHead3\">\u4f7f\u7528HttpCalloutMock\u6d4b\u8bd5\u5916\u547c<\/h3>\n<p class=\"p\">\u4e3a\u4e86\u6d4b\u8bd5\u4f60\u7684POST\u6807\u6ce8\uff0c\u6211\u4eec\u63d0\u4f9b\u4e86\u4e00\u4e2aHttpCalloutMock\u63a5\u53e3\u7684\u5b9e\u73b0\u3002\u6b64\u63a5\u53e3\u4f7f\u60a8\u80fd\u591f\u6307\u5b9a\u5728\u54cd\u5e94\u65b9\u6cd5\u4e2d\u53d1\u9001\u7684\u54cd\u5e94\u3002\u60a8\u7684\u6d4b\u8bd5\u7c7b\u6307\u793aApex\u8fd0\u884c\u65f6\u901a\u8fc7\u518d\u6b21\u8c03\u7528Test.setMock\u53d1\u9001\u6b64\u5047\u54cd\u5e94\u3002\u5bf9\u4e8e\u7b2c\u4e00\u4e2a\u53c2\u6570\uff0c\u4f20\u9012HttpCalloutMock.class\u3002\u5bf9\u4e8e\u7b2c\u4e8c\u4e2a\u53c2\u6570\uff0c\u4f20\u9012\u4e00\u4e2aAnimalsHttpCalloutMock\u7684\u65b0\u5b9e\u4f8b\uff0c\u5b83\u662f\u60a8\u7684HttpCalloutMock\u7684\u63a5\u53e3\u5b9e\u73b0\u3002 \uff08\u5728\u8fd9\u4e2a\u4f8b\u5b50\u4e4b\u540e\u7684\u4f8b\u5b50\u4e2d\uff0c\u6211\u4eec\u5c06\u5199AnimalsHttpCalloutMock\uff09<\/p>\n<div class=\"codeblock\">\n<div id=\"highlighter_861089\" class=\"syntaxhighlighter \">\n<div class=\"bar\">\n<div class=\"toolbar\">\n<div class=\"item copyToClipboard\">Test.setMock(HttpCalloutMock.class, new AnimalsHttpCalloutMock());<\/div>\n<\/div>\n<\/div>\n<div class=\"lines\"><\/div>\n<\/div>\n<\/div>\n<p class=\"p\">\u73b0\u5728\u6dfb\u52a0\u5b9e\u73b0HttpCalloutMock\u63a5\u53e3\u7684\u7c7b\u6765\u62e6\u622a\u6807\u6ce8\u3002\u5982\u679c\u5728\u6d4b\u8bd5\u4e0a\u4e0b\u6587\u4e2d\u8c03\u7528HTTP\u6807\u6ce8\uff0c\u5219\u4e0d\u4f1a\u8fdb\u884c\u6807\u6ce8\u3002\u76f8\u53cd\uff0c\u60a8\u4f1a\u6536\u5230\u60a8\u5728AnimalsHttpCalloutMock\u4e2d\u7684\u54cd\u5e94\u65b9\u6cd5\u5b9e\u73b0\u4e2d\u6307\u5b9a\u7684\u6a21\u62df\u54cd\u5e94\u3002<\/p>\n<ol id=\"ol_xjc_srn_c5\" class=\"ol enumList\">\n<li class=\"li\">\u5728\u5f00\u53d1\u8005\u63a7\u5236\u53f0\u4e2d\uff0c\u9009\u62e9 <span class=\"ph menucascade\"><strong class=\"ph uicontrol\">File<\/strong>\u00a0|\u00a0<strong class=\"ph uicontrol\">New<\/strong>\u00a0|\u00a0<strong class=\"ph uicontrol\">Apex Class<\/strong><\/span>.<\/li>\n<li class=\"li\">\u5bf9\u4e8e\u7c7b\u540d\uff0c\u8f93\u5165 <kbd class=\"ph userinput\">AnimalsHttpCalloutMock\u7136\u540e\u5355\u51fb<\/kbd><strong class=\"ph uicontrol\">OK<\/strong>.<\/li>\n<li class=\"li\">\u81ea\u52a8\u751f\u6210\u7684\u4ee3\u7801\u66ff\u6362\u4e3a\u4ee5\u4e0b\u7c7b\u5b9a\u4e49\u3002\n<div class=\"codeblock\">\n<div id=\"highlighter_627787\" class=\"syntaxhighlighter \">\n<div class=\"bar \">\n<div class=\"toolbar\">@isTest<br \/>\nglobal class AnimalsHttpCalloutMock implements HttpCalloutMock {<br \/>\n\/\/ \u5b9e\u73b0\u8fd9\u4e2a\u63a5\u53e3\u65b9\u6cd5<br \/>\nglobal HTTPResponse respond(HTTPRequest request) {<br \/>\n\/\/ \u521b\u5efa\u4e00\u4e2a\u5047\u7684\u56de\u5e94<br \/>\nHttpResponse response = new HttpResponse();<br \/>\nresponse.setHeader(&#8216;Content-Type&#8217;, &#8216;application\/json&#8217;);<br \/>\nresponse.setBody(&#8216;{&#8220;animals&#8221;: [&#8220;majestic badger&#8221;, &#8220;fluffy bunny&#8221;, &#8220;scary bear&#8221;, &#8220;chicken&#8221;, &#8220;mighty moose&#8221;]}&#8217;);<br \/>\nresponse.setStatusCode(200);<br \/>\nreturn response;<br \/>\n}<br \/>\n}<\/div>\n<\/div>\n<div class=\"lines\"><\/div>\n<\/div>\n<\/div>\n<\/li>\n<li class=\"li\">\u70b9\u51fb<strong class=\"ph uicontrol\">CTRL+S<\/strong>\u4fdd\u5b58.<\/li>\n<\/ol>\n<p class=\"p\">\u5728\u60a8\u7684\u6d4b\u8bd5\u7c7b\u4e2d\uff0c\u521b\u5efatestPostCallout\u65b9\u6cd5\u6765\u8bbe\u7f6e\u6a21\u62df\u6807\u6ce8\uff0c\u5982\u4e0b\u4f8b\u6240\u793a\u3002 testPostCallout\u65b9\u6cd5\u8c03\u7528Test.setMock\uff0c\u7136\u540e\u8c03\u7528AnimalsCallouts\u7c7b\u4e2d\u7684makePostCallout\u65b9\u6cd5\u3002\u7136\u540e\u9a8c\u8bc1\u8fd4\u56de\u7684\u54cd\u5e94\u662f\u60a8\u5728\u6a21\u62df\u5b9e\u73b0\u7684\u54cd\u5e94\u65b9\u6cd5\u4e2d\u6307\u5b9a\u7684\u3002<\/p>\n<ol id=\"ol_s3d_fsn_c5\" class=\"ol enumList\">\n<li class=\"li\">\u4fee\u6539\u6d4b\u8bd5\u7c7bAnimalsCalloutsTest\u6dfb\u52a0\u7b2c\u4e8c\u4e2a\u6d4b\u8bd5\u65b9\u6cd5\u3002\u5355\u51fb\u7c7b\u9009\u9879\u5361\uff0c\u7136\u540e\u5728\u53f3\u62ec\u53f7\u4e4b\u524d\u6dfb\u52a0\u4ee5\u4e0b\u65b9\u6cd5\u3002\n<div class=\"codeblock\">\n<div id=\"highlighter_897923\" class=\"syntaxhighlighter \">\n<div class=\"bar \">\n<div class=\"toolbar\">@isTest static void testPostCallout() {<br \/>\n\/\/ \u8bbe\u7f6e\u6a21\u62df\u5916\u547c\u7c7b<br \/>\nTest.setMock(HttpCalloutMock.class, new AnimalsHttpCalloutMock());<br \/>\n\/\/\u8fd9\u4f1a\u5bfc\u81f4\u4e00\u4e2a\u5047\u7684\u54cd\u5e94\u88ab\u53d1\u9001<br \/>\n\/\/ \u4ece\u5b9e\u73b0HttpCalloutMock\u7684\u7c7b\u4e2d<br \/>\nHttpResponse response = AnimalsCallouts.makePostCallout();<br \/>\n\/\/\u9a8c\u8bc1\u6536\u5230\u7684\u54cd\u5e94\u662f\u5426\u5305\u542b\u5047\u503c<br \/>\nString contentType = response.getHeader(&#8216;Content-Type&#8217;);<br \/>\nSystem.assert(contentType == &#8216;application\/json&#8217;);<br \/>\nString actualValue = response.getBody();<br \/>\nSystem.debug(response.getBody());<br \/>\nString expectedValue = &#8216;{&#8220;animals&#8221;: [&#8220;majestic badger&#8221;, &#8220;fluffy bunny&#8221;, &#8220;scary bear&#8221;, &#8220;chicken&#8221;, &#8220;mighty moose&#8221;]}&#8217;;<br \/>\nSystem.assertEquals(actualValue, expectedValue);<br \/>\nSystem.assertEquals(200, response.getStatusCode());<br \/>\n}<\/div>\n<div class=\"toolbar\"><\/div>\n<\/div>\n<div class=\"lines\"><\/div>\n<\/div>\n<\/div>\n<\/li>\n<li class=\"li\"><span class=\"ph uicontrol\">\u70b9\u51fb<\/span><strong class=\"ph uicontrol\">CTRL+S<\/strong>\u00a0\u4fdd\u5b58.<\/li>\n<li class=\"li\">\u9009\u62e9\u00a0<span class=\"ph menucascade\"><strong class=\"ph uicontrol\">Test<\/strong>\u00a0|\u00a0<strong class=\"ph uicontrol\">New Run<\/strong><\/span>.<\/li>\n<li class=\"li\">\u4eceTest Classes\u5217\u8868\u4e2d\u9009\u62e9<strong class=\"ph uicontrol\">AnimalsCalloutsTest<\/strong>.<\/li>\n<li class=\"li\">\u70b9\u51fb\u00a0<span class=\"ph menucascade\"><strong class=\"ph uicontrol\">Add Selected<\/strong>\u00a0|\u00a0<strong class=\"ph uicontrol\">Run<\/strong><\/span>.\n<p class=\"p\">\u6d4b\u8bd5\u7ed3\u679c\u663e\u793a\u5728\u201c\u6d4b\u8bd5\u201d\u9009\u9879\u5361\u4e0b\u7684\u65b0\u6d4b\u8bd5\u8fd0\u884cID\u4e0b\u3002\u5f53\u6d4b\u8bd5\u6267\u884c\u5b8c\u6210\u65f6\uff0c\u5c55\u5f00\u6d4b\u8bd5\u8fd0\u884c\u4ee5\u67e5\u770b\u6709\u5173\u8fd9\u4e24\u4e2a\u6d4b\u8bd5\u7684\u8be6\u7ec6\u4fe1\u606f\u3002<\/p>\n<\/li>\n<\/ol>\n<\/div>\n<\/div>\n<\/div>\n<div id=\"apex_integration_rest_tell_me_more\" class=\"topic concept nested0\" lang=\"en-us\" xml:lang=\"en-us\">\n<h2 id=\"Tdxn4tBK-heading10\" class=\"helpHead2\"><span id=\"topic-title\" class=\"ph\">\u66f4\u591a&#8230;<\/span><\/h2>\n<div class=\"body conbody\">\n<div class=\"shortdesc\">\n<p>\u4e86\u89e3\u5982\u4f55\u5728\u89e6\u53d1\u5668\u548c\u5f02\u6b65Apex\u4e2d\u4f7f\u7528\u6807\u6ce8\uff0c\u4ee5\u53ca\u5982\u4f55\u5236\u4f5c\u5f02\u6b65\u6807\u6ce8\u3002<br \/>\n\u5f53\u4ece\u4e00\u4e2a\u65b9\u6cd5\u8fdb\u884c\u6807\u6ce8\u65f6\uff0c\u8be5\u65b9\u6cd5\u5728\u6267\u884c\u540e\u7eed\u4ee3\u7801\u884c\u4e4b\u524d\uff0c\u7b49\u5f85\u5916\u90e8\u670d\u52a1\u53d1\u56de\u6807\u6ce8\u54cd\u5e94\u3002\u6216\u8005\uff0c\u60a8\u53ef\u4ee5\u5c06\u6807\u6ce8\u4ee3\u7801\u7f6e\u4e8e\u7528@future\uff08callout = true\uff09\u6ce8\u91ca\u7684\u5f02\u6b65\u65b9\u6cd5\u4e2d\uff0c\u6216\u8005\u4f7f\u7528Queueable Apex\u3002\u8fd9\u6837\uff0c\u6807\u6ce8\u5728\u5355\u72ec\u7684\u7ebf\u7a0b\u4e0a\u8fd0\u884c\uff0c\u8c03\u7528\u65b9\u6cd5\u7684\u6267\u884c\u4e0d\u4f1a\u88ab\u963b\u6b62\u3002<\/p>\n<p>\u4ece\u89e6\u53d1\u5668\u8fdb\u884c\u6807\u6ce8\u65f6\uff0c\u6807\u6ce8\u4e0d\u5f97\u5728\u7b49\u5f85\u54cd\u5e94\u65f6\u963b\u6b62\u89e6\u53d1\u8fc7\u7a0b\u3002\u4e3a\u4e86\u4f7f\u89e6\u53d1\u5668\u80fd\u591f\u8fdb\u884c\u6807\u6ce8\uff0c\u5305\u542b\u6807\u6ce8\u4ee3\u7801\u7684\u65b9\u6cd5\u5fc5\u987b\u4f7f\u7528@future\uff08callout = true\uff09\u8fdb\u884c\u6ce8\u91ca\uff0c\u4ee5\u4fbf\u5728\u5355\u72ec\u7684\u7ebf\u7a0b\u4e2d\u8fd0\u884c\u3002<\/p>\n<h2>\u81ea\u5df1\u52a8\u624b\u5c1d\u8bd5<\/h2>\n<p>\u521b\u5efa\u4e00\u4e2a\u8c03\u7528REST\u7aef\u70b9\u7684Apex\u7c7b\u5e76\u7f16\u5199\u4e00\u4e2a\u6d4b\u8bd5\u7c7b\u3002<\/p>\n<p>\u4e3a\u4e86\u901a\u8fc7\u8fd9\u4e2a\u7ec3\u4e60\uff0c\u521b\u5efa\u4e00\u4e2a\u8c03\u7528REST\u7aef\u70b9\u7684Apex\u7c7b\u6765\u8fd4\u56de\u4e00\u4e2a\u52a8\u7269\u7684\u540d\u5b57\uff0c\u7f16\u5199\u5355\u5143\u6d4b\u8bd5\uff0c\u4f7f\u7528\u6a21\u62df\u54cd\u5e94\u5b9e\u73b0\u7c7b\u7684100\uff05\u4ee3\u7801\u8986\u76d6\u7387\uff0c\u5e76\u8fd0\u884cApex\u6d4b\u8bd5\u3002<\/p>\n<ul>\n<li>Apex\u7c7b\u5fc5\u987b\u88ab\u79f0\u4e3a\u201cAnimalLocator\u201d\uff0c\u6709\u4e00\u4e2a\u201cgetAnimalNameById\u201d\u65b9\u6cd5\u63a5\u53d7\u4e00\u4e2aInteger\u5e76\u8fd4\u56de\u4e00\u4e2aString\u3002<\/li>\n<li>&#8216;getAnimalNameById&#8217;\u65b9\u6cd5\u5fc5\u987b\u4f7f\u7528\u4f20\u5165\u65b9\u6cd5\u7684ID\u8c03\u7528https:\/\/th-apex-http-callout.herokuapp.com\/animals\/:id\u3002 \u8be5\u65b9\u6cd5\u8fd4\u56de\u201cname\u201d\u5c5e\u6027\uff08\u5373\u52a8\u7269\u540d\u79f0\uff09\u7684\u503c\u3002<\/li>\n<li>\u521b\u5efa\u4e00\u4e2a\u540d\u4e3aAnimalLocatorTest\u7684\u6d4b\u8bd5\u7c7b\uff0c\u8be5\u7c7b\u4f7f\u7528\u540d\u4e3aAnimalLocatorMock\u7684\u6a21\u62df\u7c7b\u6a21\u62df\u6807\u6ce8\u54cd\u5e94\u3002<\/li>\n<li>\u5355\u5143\u6d4b\u8bd5\u5fc5\u987b\u6db5\u76d6AnimalLocator\u7c7b\u4e2d\u5305\u542b\u7684\u6240\u6709\u4ee3\u7801\u884c\uff0c\u4ece\u800c\u5f97\u5230100\uff05\u7684\u4ee3\u7801\u8986\u76d6\u7387\u3002<\/li>\n<li>R\u5728\u5c1d\u8bd5\u9a8c\u8bc1\u8fd9\u4e2a\u6311\u6218\u4e4b\u524d\uff0c\u81f3\u5c11\u8fd0\u884c\u4e00\u6b21\u6d4b\u8bd5\u7c7b\uff08\u901a\u8fc7\u201c\u5168\u90e8\u8fd0\u884c\u201d\u6d4b\u8bd5\u5f00\u53d1\u8005\u63a7\u5236\u53f0\uff09\u3002<\/li>\n<\/ul>\n<\/div>\n<\/div>\n<\/div>\n","protected":false},"excerpt":{"rendered":"<p>\u5b66\u4e60\u76ee\u6807 \u5b8c\u6210\u540e\uff0c\u60a8\u5c06\u80fd\u591f\uff1a \u6267\u884c\u5916\u547c\u4ee5\u63a5\u6536\u6765\u81ea\u5916\u90e8\u670d\u52a1\u7684\u6570\u636e\u3002 \u6267\u884c\u5916\u547c\u5c06\u6570\u636e\u53d1\u9001\u5230\u5916\u90e8\u670d\u52a1\u3002 \u4f7f\u7528\u6a21\u62df\u6807\u6ce8 &hellip; <a href=\"http:\/\/www.ponybai.com\/?p=169\" class=\"more-link\">\u7ee7\u7eed\u9605\u8bfb<span class=\"screen-reader-text\">Apex REST\u5916\u90e8\u8c03\u7528<\/span><\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[82],"tags":[],"class_list":["post-169","post","type-post","status-publish","format-standard","hentry","category-salesforce-api"],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v21.7 - https:\/\/yoast.com\/wordpress\/plugins\/seo\/ -->\n<title>Apex REST\u5916\u90e8\u8c03\u7528 - \u767d\u767d\u968f\u7b14<\/title>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"http:\/\/www.ponybai.com\/?p=169\" \/>\n<meta property=\"og:locale\" content=\"zh_CN\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"Apex REST\u5916\u90e8\u8c03\u7528 - \u767d\u767d\u968f\u7b14\" \/>\n<meta property=\"og:description\" content=\"\u5b66\u4e60\u76ee\u6807 \u5b8c\u6210\u540e\uff0c\u60a8\u5c06\u80fd\u591f\uff1a \u6267\u884c\u5916\u547c\u4ee5\u63a5\u6536\u6765\u81ea\u5916\u90e8\u670d\u52a1\u7684\u6570\u636e\u3002 \u6267\u884c\u5916\u547c\u5c06\u6570\u636e\u53d1\u9001\u5230\u5916\u90e8\u670d\u52a1\u3002 \u4f7f\u7528\u6a21\u62df\u6807\u6ce8 &hellip; \u7ee7\u7eed\u9605\u8bfbApex REST\u5916\u90e8\u8c03\u7528\" \/>\n<meta property=\"og:url\" content=\"http:\/\/www.ponybai.com\/?p=169\" \/>\n<meta property=\"og:site_name\" content=\"\u767d\u767d\u968f\u7b14\" \/>\n<meta property=\"article:published_time\" content=\"2017-12-07T11:48:22+00:00\" \/>\n<meta property=\"og:image\" content=\"https:\/\/res.cloudinary.com\/hy4kyit2a\/image\/upload\/doc\/trailhead\/en-us9e44c283a52e2f5ac41ea9d332799104.png\" \/>\n<meta name=\"author\" content=\"ponybai\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:label1\" content=\"\u4f5c\u8005\" \/>\n\t<meta name=\"twitter:data1\" content=\"ponybai\" \/>\n\t<meta name=\"twitter:label2\" content=\"\u9884\u8ba1\u9605\u8bfb\u65f6\u95f4\" \/>\n\t<meta name=\"twitter:data2\" content=\"4 \u5206\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\/\/schema.org\",\"@graph\":[{\"@type\":\"Article\",\"@id\":\"http:\/\/www.ponybai.com\/?p=169#article\",\"isPartOf\":{\"@id\":\"http:\/\/www.ponybai.com\/?p=169\"},\"author\":{\"name\":\"ponybai\",\"@id\":\"http:\/\/www.ponybai.com\/#\/schema\/person\/935c7592c850c65e1e5eba4530dbf883\"},\"headline\":\"Apex REST\u5916\u90e8\u8c03\u7528\",\"datePublished\":\"2017-12-07T11:48:22+00:00\",\"dateModified\":\"2017-12-07T11:48:22+00:00\",\"mainEntityOfPage\":{\"@id\":\"http:\/\/www.ponybai.com\/?p=169\"},\"wordCount\":721,\"publisher\":{\"@id\":\"http:\/\/www.ponybai.com\/#\/schema\/person\/935c7592c850c65e1e5eba4530dbf883\"},\"articleSection\":[\"Salesforce-API\"],\"inLanguage\":\"zh-Hans\"},{\"@type\":\"WebPage\",\"@id\":\"http:\/\/www.ponybai.com\/?p=169\",\"url\":\"http:\/\/www.ponybai.com\/?p=169\",\"name\":\"Apex REST\u5916\u90e8\u8c03\u7528 - \u767d\u767d\u968f\u7b14\",\"isPartOf\":{\"@id\":\"http:\/\/www.ponybai.com\/#website\"},\"datePublished\":\"2017-12-07T11:48:22+00:00\",\"dateModified\":\"2017-12-07T11:48:22+00:00\",\"breadcrumb\":{\"@id\":\"http:\/\/www.ponybai.com\/?p=169#breadcrumb\"},\"inLanguage\":\"zh-Hans\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"http:\/\/www.ponybai.com\/?p=169\"]}]},{\"@type\":\"BreadcrumbList\",\"@id\":\"http:\/\/www.ponybai.com\/?p=169#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"\u9996\u9875\",\"item\":\"http:\/\/www.ponybai.com\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"Apex REST\u5916\u90e8\u8c03\u7528\"}]},{\"@type\":\"WebSite\",\"@id\":\"http:\/\/www.ponybai.com\/#website\",\"url\":\"http:\/\/www.ponybai.com\/\",\"name\":\"\u767d\u767d\u968f\u7b14\",\"description\":\"Salesforce\u5b98\u65b9\u8bb2\u5e08\",\"publisher\":{\"@id\":\"http:\/\/www.ponybai.com\/#\/schema\/person\/935c7592c850c65e1e5eba4530dbf883\"},\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"http:\/\/www.ponybai.com\/?s={search_term_string}\"},\"query-input\":\"required name=search_term_string\"}],\"inLanguage\":\"zh-Hans\"},{\"@type\":[\"Person\",\"Organization\"],\"@id\":\"http:\/\/www.ponybai.com\/#\/schema\/person\/935c7592c850c65e1e5eba4530dbf883\",\"name\":\"ponybai\",\"image\":{\"@type\":\"ImageObject\",\"inLanguage\":\"zh-Hans\",\"@id\":\"http:\/\/www.ponybai.com\/#\/schema\/person\/image\/\",\"url\":\"http:\/\/www.ponybai.com\/wp-content\/uploads\/2025\/03\/cropped-Ihsans-WeChatQR.jpg\",\"contentUrl\":\"http:\/\/www.ponybai.com\/wp-content\/uploads\/2025\/03\/cropped-Ihsans-WeChatQR.jpg\",\"width\":248,\"height\":248,\"caption\":\"ponybai\"},\"logo\":{\"@id\":\"http:\/\/www.ponybai.com\/#\/schema\/person\/image\/\"},\"sameAs\":[\"http:\/\/121.37.188.161\"],\"url\":\"http:\/\/www.ponybai.com\/?author=1\"}]}<\/script>\n<!-- \/ Yoast SEO plugin. -->","yoast_head_json":{"title":"Apex REST\u5916\u90e8\u8c03\u7528 - \u767d\u767d\u968f\u7b14","robots":{"index":"index","follow":"follow","max-snippet":"max-snippet:-1","max-image-preview":"max-image-preview:large","max-video-preview":"max-video-preview:-1"},"canonical":"http:\/\/www.ponybai.com\/?p=169","og_locale":"zh_CN","og_type":"article","og_title":"Apex REST\u5916\u90e8\u8c03\u7528 - \u767d\u767d\u968f\u7b14","og_description":"\u5b66\u4e60\u76ee\u6807 \u5b8c\u6210\u540e\uff0c\u60a8\u5c06\u80fd\u591f\uff1a \u6267\u884c\u5916\u547c\u4ee5\u63a5\u6536\u6765\u81ea\u5916\u90e8\u670d\u52a1\u7684\u6570\u636e\u3002 \u6267\u884c\u5916\u547c\u5c06\u6570\u636e\u53d1\u9001\u5230\u5916\u90e8\u670d\u52a1\u3002 \u4f7f\u7528\u6a21\u62df\u6807\u6ce8 &hellip; \u7ee7\u7eed\u9605\u8bfbApex REST\u5916\u90e8\u8c03\u7528","og_url":"http:\/\/www.ponybai.com\/?p=169","og_site_name":"\u767d\u767d\u968f\u7b14","article_published_time":"2017-12-07T11:48:22+00:00","og_image":[{"url":"https:\/\/res.cloudinary.com\/hy4kyit2a\/image\/upload\/doc\/trailhead\/en-us9e44c283a52e2f5ac41ea9d332799104.png"}],"author":"ponybai","twitter_card":"summary_large_image","twitter_misc":{"\u4f5c\u8005":"ponybai","\u9884\u8ba1\u9605\u8bfb\u65f6\u95f4":"4 \u5206"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"Article","@id":"http:\/\/www.ponybai.com\/?p=169#article","isPartOf":{"@id":"http:\/\/www.ponybai.com\/?p=169"},"author":{"name":"ponybai","@id":"http:\/\/www.ponybai.com\/#\/schema\/person\/935c7592c850c65e1e5eba4530dbf883"},"headline":"Apex REST\u5916\u90e8\u8c03\u7528","datePublished":"2017-12-07T11:48:22+00:00","dateModified":"2017-12-07T11:48:22+00:00","mainEntityOfPage":{"@id":"http:\/\/www.ponybai.com\/?p=169"},"wordCount":721,"publisher":{"@id":"http:\/\/www.ponybai.com\/#\/schema\/person\/935c7592c850c65e1e5eba4530dbf883"},"articleSection":["Salesforce-API"],"inLanguage":"zh-Hans"},{"@type":"WebPage","@id":"http:\/\/www.ponybai.com\/?p=169","url":"http:\/\/www.ponybai.com\/?p=169","name":"Apex REST\u5916\u90e8\u8c03\u7528 - \u767d\u767d\u968f\u7b14","isPartOf":{"@id":"http:\/\/www.ponybai.com\/#website"},"datePublished":"2017-12-07T11:48:22+00:00","dateModified":"2017-12-07T11:48:22+00:00","breadcrumb":{"@id":"http:\/\/www.ponybai.com\/?p=169#breadcrumb"},"inLanguage":"zh-Hans","potentialAction":[{"@type":"ReadAction","target":["http:\/\/www.ponybai.com\/?p=169"]}]},{"@type":"BreadcrumbList","@id":"http:\/\/www.ponybai.com\/?p=169#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"\u9996\u9875","item":"http:\/\/www.ponybai.com\/"},{"@type":"ListItem","position":2,"name":"Apex REST\u5916\u90e8\u8c03\u7528"}]},{"@type":"WebSite","@id":"http:\/\/www.ponybai.com\/#website","url":"http:\/\/www.ponybai.com\/","name":"\u767d\u767d\u968f\u7b14","description":"Salesforce\u5b98\u65b9\u8bb2\u5e08","publisher":{"@id":"http:\/\/www.ponybai.com\/#\/schema\/person\/935c7592c850c65e1e5eba4530dbf883"},"potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"http:\/\/www.ponybai.com\/?s={search_term_string}"},"query-input":"required name=search_term_string"}],"inLanguage":"zh-Hans"},{"@type":["Person","Organization"],"@id":"http:\/\/www.ponybai.com\/#\/schema\/person\/935c7592c850c65e1e5eba4530dbf883","name":"ponybai","image":{"@type":"ImageObject","inLanguage":"zh-Hans","@id":"http:\/\/www.ponybai.com\/#\/schema\/person\/image\/","url":"http:\/\/www.ponybai.com\/wp-content\/uploads\/2025\/03\/cropped-Ihsans-WeChatQR.jpg","contentUrl":"http:\/\/www.ponybai.com\/wp-content\/uploads\/2025\/03\/cropped-Ihsans-WeChatQR.jpg","width":248,"height":248,"caption":"ponybai"},"logo":{"@id":"http:\/\/www.ponybai.com\/#\/schema\/person\/image\/"},"sameAs":["http:\/\/121.37.188.161"],"url":"http:\/\/www.ponybai.com\/?author=1"}]}},"_links":{"self":[{"href":"http:\/\/www.ponybai.com\/index.php?rest_route=\/wp\/v2\/posts\/169","targetHints":{"allow":["GET"]}}],"collection":[{"href":"http:\/\/www.ponybai.com\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"http:\/\/www.ponybai.com\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"http:\/\/www.ponybai.com\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"http:\/\/www.ponybai.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=169"}],"version-history":[{"count":0,"href":"http:\/\/www.ponybai.com\/index.php?rest_route=\/wp\/v2\/posts\/169\/revisions"}],"wp:attachment":[{"href":"http:\/\/www.ponybai.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=169"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"http:\/\/www.ponybai.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=169"},{"taxonomy":"post_tag","embeddable":true,"href":"http:\/\/www.ponybai.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=169"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}