¿ìËÙÒµÎñͨµÀ

¾«Í¨Grails: RESTful Grails - ±à³ÌÈëÃÅÍø

×÷Õß ØýÃû¼¼Êõ À´Ô´ NET±à³Ì ä¯ÀÀ ·¢²¼Ê±¼ä 2012-06-15
port/list£¬²¢ÑéÖ¤ Accept ±¨Í·ÕýÔÚÇëÇó text/xml ¡£Õâ¾ÍÊÇ×ÊÔ´µÄ MIME ÀàÐÍÁË¡£

ÄÇô£¬Grails ÊÇÈçºÎÏìÓ¦·þÎñÆ÷¶ËµÄ Accept ±¨Í·µÄÄØ£¿ÔÙÏò AirportController Ìí¼ÓÒ»¸ö±Õ°ü£¬ ÈçÇåµ¥ 4 Ëùʾ£º

Çåµ¥ 4. debugAccept ²Ù×÷

def¡¡debugAccept¡¡=¡¡{ ¡¡ def¡¡clientRequest¡¡=¡¡request.getHeader("accept") ¡¡ def¡¡serverResponse¡¡=¡¡request.format ¡¡ render¡¡"Client:¡¡${clientRequest}\nServer:¡¡${serverResponse}\n" }

Çåµ¥ 4 ÖеĵÚÒ»ÐдÓÇëÇóÖмìË÷³öÁË Accept ±¨Í·¡£µÚ¶þÐÐչʾÁË Grails ÈçºÎת»»ÇëÇóºÍËü½«Òª·¢ »ØµÄÏìÓ¦¡£

ÏÖÔÚ£¬Ê¹Óà cURL À´×öÏàͬµÄËÑË÷£¬ÈçÇåµ¥ 5 Ëùʾ£º

Çåµ¥ 5. µ÷ÊÔ cURL ÖÐµÄ Accept ±¨Í·

$¡¡curl¡¡ http://localhost:9090/trip/airport/debugAccept Client:¡¡*/* Server:¡¡all $¡¡curl¡¡--header¡¡Accept:text/xml¡¡http://localhost:9090/trip/airport/debugAccept Client:¡¡text/xml Server:¡¡xml

¾«Í¨Grails: RESTful Grails(6)

ʱ¼ä:2011-07-29 IBM Scott Davis

all ºÍ xml ÖµÊÇÄÄÀ´µÄÄØ£¿¿´Ò»Ï grails-app/conf/Config.groovy¡£ÔÚÎļþ¶¥²¿£¬ÄúÓ¦¸Ã¿´µ½ÁËÒ» ¸öÉ¢ÁÐÓ³É䣬Ëü¶ÔËùÓеļü¶¼Ê¹ÓÃÁ˼òµ¥Ãû³Æ£¨Ïñ all ºÍ xml ÕâÑùµÄÃû³Æ£©£¬¶øÇÒËùÓеÄÖµ¶¼Ê¹ÓÃÁËÓë Ö®¶ÔÓ¦µÄ MIME ÀàÐÍ¡£Çåµ¥ 6 չʾÁË grails.mime.types É¢ÁÐÓ³É䣺

Çåµ¥ 6. Config.groovy ÖÐµÄ grails.mime.types É¢ÁÐ

grails.mime.types¡¡=¡¡[¡¡html: ¡¡[''text/html'',''application/xhtml+xml''], ¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡ xml:¡¡[''text/xml'',¡¡''application/xml''], ¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡ text:¡¡''text-plain'', ¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡ js:¡¡''text/javascript'', ¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡ rss:¡¡''application/rss+xml'', ¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡ atom:¡¡''application/atom+xml'', ¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡ css:¡¡''text/css'', ¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡ csv:¡¡''text/csv'', ¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡ all:¡¡''*/*'', ¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡ json:¡¡[''application/json'',''text/json''], ¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡ form:¡¡''application/x-www-form-urlencoded'', ¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡ multipartForm:¡¡''multipart/form-data'' ¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡ ] ¸ß¼¶µÄÄÚÈÝЭÉÌ

µäÐ굀 Web ä¯ÀÀÆ÷ÌṩµÄ Accept ±¨Í·Òª±ÈÄúÓë cURL Ò»ÆðʹÓõÄÉÔ΢¸´ÔÓЩ¡£ÀýÈ磬Mac OS X 10.5.4 É쵀 Firefox 3.0.1 ÌṩµÄ Accept ±¨Í·´óÖÂÊÇÕâÑùµÄ£º

text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8

ËüÊÇÒ»¸öÓöººÅ¸ô¿ªµÄÁÐ±í£¬Ëü´øÓпÉÑ¡µÄ q ÊôÐÔ£¬ÓÃÒÔÖ§³Ö MIME ÀàÐÍ£¨q Öµ — quality µÄËõд — ÊÇ float Öµ£¬·¶Î§ÊÇ 0.0 µ½ 1.0£©¡£ÓÉÓÚ application/xml ±»¸³ÓèÁËÒ»¸öΪ 0.9 µÄ q Öµ£¬ËùÒÔÓë ÆäËûÀàÐ͵ÄÊý¾ÝÏà±È£¬Firefox ¸üÆ«ºÃ XML Êý¾Ý¡£

ÏÂÃæÊÇ Mac OS X 10.5.4 É쵀 Safari 3.1.2 °æ±¾ÌṩµÄ accept ±¨Í·£º

text/xml,application/xml,application/xhtml+xml, ¡¡¡¡¡¡ text/html;q=0.9,text/plain;q=0.8,image/png,*/*;q=0.5

text/html MIME ÀàÐͱ»¸³ÓèÁËÒ»¸öΪ 0.9 µÄ q Öµ£¬ËùÒÔÊ×Ñ¡µÄÊä³öÀàÐÍÊÇ HTML£¬0.8 ʱΪ text/plain£¬0.5 ʱΪ */*¡£

ÄÇô£¬ÏÖÔÚÄúÓ¦¸Ã¶ÔÄÚÈÝЭÉÌÓÐÁ˸ü¶àµÄÁ˽âÁË£¬Äú¿ÉÒÔ½« withFormat ¿éÌí¼Óµ½ list ²Ù×÷£¬ÒÔ´Ë À´ÒÀ¾ÝÇëÇóÖÐµÄ Accept ±¨Í··µ»ØºÏÊʵÄÊý¾ÝÀàÐÍ£¬ÈçÇåµ¥ 7 Ëùʾ£º

Çåµ¥ 7. ÔÚÒ»¸ö²Ù×÷ÖÐʹÓà withFormat ¿é

def¡¡list¡¡=¡¡{ ¡¡ if(!params.max)¡¡params.max¡¡=¡¡10 ¡¡ def¡¡list¡¡=¡¡Airport.list(params) ¡¡ withFormat{ ¡¡¡¡ html{ ¡¡¡¡¡¡ return¡¡[airportList:list] ¡¡¡¡ } ¡¡¡¡ xml{ ¡¡¡¡¡¡ render¡¡list¡¡as¡¡XML

ÁèÖڿƼ¼×¨ÒµÌṩ·þÎñÆ÷×âÓᢷþÎñÆ÷Íйܡ¢ÆóÒµÓʾ֡¢ÐéÄâÖ÷»úµÈ·þÎñ£¬¹«Ë¾ÍøÕ¾£ºhttp://www.lingzhong.cn ΪÁ˸ø¹ã´ó¿Í»§Á˽â¸ü¶àµÄ¼¼ÊõÐÅÏ¢£¬±¾¼¼ÊõÎÄÕÂÊÕ¼¯À´Ô´ÓÚÍøÂç,ÁèÖڿƼ¼×ðÖØÎÄÕÂ×÷ÕߵİæȨ£¬Èç¹ûÓÐÉæ¼°ÄãµÄ°æȨÓбØҪɾ³ýÄãµÄÎÄÕ£¬ÇëºÍÎÒÃÇÁªÏµ¡£ÒÔÉÏÐÅÏ¢ÓëÎÄÕÂÕýÎÄÊDz»¿É·Ö¸îµÄÒ»²¿·Ö,Èç¹ûÄúҪתÔر¾ÎÄÕÂ,Çë±£ÁôÒÔÉÏÐÅÏ¢£¬Ð»Ð»!

·ÖÏíµ½£º ¸ü¶à
Äã¿ÉÄܶÔÏÂÃæµÄÎÄÕ¸ÐÐËȤ
HTTP/1.1 401 Access Denied Ƹ߹âË®¾§ÖʸÐË®¾§Æ»¹û" target="_blank">Photoshop»æÖƸ߹âË®¾§ÖʸÐË®¾§Æ»¹û

Copyright ©1999-2011 ÏÃÃÅÁèÖڿƼ¼ÓÐÏÞ¹«Ë¾ ÏÃÃÅÓÅͨ»¥Áª¿Æ¼¼¿ª·¢ÓÐÏÞ¹«Ë¾ All rights reserved

µØÖ·(ADD)£ºÏÃÃÅÈí¼þÔ°¶þÆÚÍûº£Â·63ºÅ701E£¨¶«ÄÏÈÚͨÅÔ£© Óʱà(ZIP)£º361008

µç»°£º0592-5908028 ´«Õ棺0592-5908039 ×ÉѯÐÅÏ䣺web@lingzhong.cn ×ÉѯOICQ£º173723134

¡¶ÖлªÈËÃñ¹²ºÍ¹úÔöÖµµçÐÅÒµÎñ¾­ÓªÐí¿ÉÖ¤¡·ÃöB2-20100024  ICP±¸°¸:ÃöICP±¸05037997ºÅ