Announcement Announcement Module
Collapse
No announcement yet.
REST client for PUT method over http Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • REST client for PUT method over http

    Hi

    I m trying to send information through REST PUT over http and I need to send the same in text/xml format. However from what i implemented below, i keep sending it in application/xml format. Can you please advice what is wrong with the code below.

    Code:
    def httpbuilder = new HTTPBuilder( "http://localhost:8080/ABCD/<URI path>")
    		httpbuilder.headers = [Accept:"text/xml"]
    		httpbuilder.setContentType("text/xml")
    
    try {
    			httpbuilder.request( PUT ) {
    				uri.path = "<URI path>"
    				send( 'text/xml' ) {
    					ROOTxml{
    						child1 {
    							child12{
    								name 'AAAA'
    								id  '1234'
    '							         }
    						         }
    					             }
    				         }
    				// success handler
    				response.success = { resp, reader ->
    					def stringWriter = new StringWriter()
    					def node = new XmlParser().parseText(reader.text);
    					new XmlNodePrinter(new PrintWriter(stringWriter)).print(node)
    					return stringWriter.toString()
    				}
    				// failure handler
    				response.failure = { resp ->
    					return 'Response status='+resp.status
    				}
    			}
Working...
X