环境:JDK1.8
编译器级别:Java 1.7
Jar文件:(1)org.restlet.ext.xml.jar文件(二)org.restlet.jar
代码:
package com.arzoo.resources;
import org.restlet.Server;
import org.restlet.data.Protocol;
import org.restlet.ext.xml.DomRepresentation;
import org.restlet.representation.Representation;
import org.restlet.resource.Post;
import org.restlet.resource.ServerResource;
public class TestXml extends ServerResource
{ public static void main(String[] args) throws Exception
{
new Server(Protocol.HTTP, 8182, TestXml.class).start();
}
@Post("xml")
public Representation doPostXml(DomRepresentation entity)
{ return entity;
}
}
来自命令行的HTTP请求:
~$ curl -i -H "Content-Type: application/xml" "http://localhost:8182" -d "<MyRoot/>"
HTTP/1.1 200 OK
Server: Restlet-Framework/2.3.12
Date: Fri, 09 Nov 2018 12:06:28 GMT
Transfer-encoding: chunked
Content-type: application/xml
Vary: Accept-Charset, Accept-Encoding, Accept-Language, Accept
<?xml version="1.0" encoding="ISO-8859-1" standalone="no"?><MyRoot/>