- 원격제어를 위한 XML 정의 스팩 (사실상의 표준)
- 원문링크 :
http://www.xmlrpc.org/spec
1 개요 #
- XML-RPC는 인터넷을 통해 전달되는 원격 프로시져 호출 프로토콜을 말합니다.
- XML-RPC 메세지는 HTTP-POST 요청으로 구성되며, 요청 본체는 XML안에 들어있습니다.
- 프로시져는 서버상에서 실행되며 반환값또한 XML 포맷을 사용합니다.
- 프로시져 매개변수들은 스칼라값, 숫자값, 문자열, 날짜 등등을 지정할 수 있습니다. 또한, 복잡한 레코드와 리스트 구조체도 지정가능합니다.
2 요청 예제 #
아래는 XML-RPC 요청 예입니다:
POST /RPC2 HTTP/1.0 User-Agent: Frontier/5.1.2 (WinNT) Host: betty.userland.com Content-Type: text/xml Content-length: 181 <?xml version="1.0"?> <methodCall> <methodName>examples.getStateName</methodName> <params> <param> <value><i4>41</i4></value> </param> </params> </methodCall>
3 헤더 요구사항 #
- 헤더 첫줄에 해당하는 URI 포멧은 별도로 정의 되어있지 않습니다. 예를 들면, 서버가 단지 XML-RPC 호출만을 다룬다면 슬래시 문자만 하나 넣어서 비워둘수 있습니다. 하지만 다른 HTTP 요청과 같이 처리하는 형태의 서버를 사용한다면 URI를 지정하여 XML-RPC 요청들을 처리하도록 가리킬수 있습니다(위 예에서는 URI는 /RPC2로 지정하여 RPC2 응답자로 요청을 전달하도록 하고 있습니다)
- User-Agent와 Host는 반드시 지정되어야만 합니다.
- Content-Type은 항상 text/xml 입니다.
- Content-Length 또한 지정되어야하며 정확해야합니다. (이 길이는 xml 문자열부분만을 나타냅니다)
4 Payload 포멧 #
- payload는 XML로 되어있으며 하나의 <methodCall> 구조체로 구성됩니다.
- <methodCall>은 호출할 메소드명을 담고있는 문자열을 나타내는 <methodName> 부속 요소를 반드시 포함해야합니다. 문자열은 단지 식별자 문자를 담고 있을수 있으며, 대소문자 A-Z, 숫자, 밑줄문자, 마침표, 콜론, 슬래시만을 사용할 수 있습니다. 이것은 전적으로 메소드명을 해독하는 서버의 기능에 따라 달라집니다. 예를 들자면, methodName은 들어오는 요청을 실행하기위한 스크립트 화일명일수도 있고, 데이타베이스 테이블의 어떤 필드명일수도 있으며, 화일과 폴더 트리안에 담겨있는 경로명일수도 있습니다.
- 프로시져 호출이 매개변수를 가지고 있다면, <methodCall>은 <params> 부속요소를 포함할 수 있습니다. <params> 부속요소는 여러개의 <param>들을 가질 수 있으며, 각각은 하나의 <value>를 가집니다.
5 스칼라 <value> 값 #
- <value>는 스칼라값이 지정될 수 있으며s can be scalars, type is indicated by nesting the value inside one of the tags listed in this table:
- 타입이 지정되어있지 않으면 기본적으로 문자열로 간주합니다.
| 테그 | 타입 | 예제 |
| <i4>또는<int> | 4바이트 부호있는 정수 | -12 |
| <boolean> | 0 (거짓) 또는 1 (참) | 1 |
| <string> | 문자열 | hello world |
| <double> | 배정도 부호있는 실수 | -12.214 |
| <dateTime.iso8601> | 시각 | 19980717T14:08:55 |
| <base64> | base64 인코딩된 이진데이타 | eW91IGNhbid0IHJlYWQgdGhpcyE= |
6 <struct> #
- 다음은 두개의 구성요소를 가진 <struct>의 예제입니다:
<struct> <member> <name>lowerBound</name> <value><i4>18</i4></value> </member> <member> <name>upperBound</name> <value><i4>139</i4></value> </member> </struct> - <value>는 또한 <struct> 타입으로 지정가능합니다.
- <struct>는 다수의 <member>들을 포함하며, 각각의 <member>는 <name>과 <value>를 각각 하나씩 담고 있습니다.
- <struct>는 재귀적으로 포함될수 있습니다. 다시말하면, 모든 <value>는 <struct>, 아래서 설명할 <array>, 그외 다른 모든 타입을 담을 수 있습니다.
7 <array> #
- 다음은 4개의 요소를 가진 <array>의 예제입니다:
<array> <data> <value><i4>12</i4></value> <value><string>Egypt</string></value> <value><boolean>0</boolean></value> <value><i4>-31</i4></value> </data> </array> - <value>는 또한 <array> 타입으로 지정가능합니다.
- <array>는 하나의 <data>를 가집니다. <data>는 다수의 <value>를 포함할 수 있습니다.
- <array>는 <name>을 포함하지 않습니다.
- You can mix types as the example above illustrates. <arrays>s can be recursive, any value may contain an <array> or any other type, including a <struct>, described above.
8 응답 예제 #
- 다음은 XML-RPC 요청에 대한 응답 예제입니다:
HTTP/1.1 200 OK Connection: close Content-Length: 158 Content-Type: text/xml Date: Fri, 17 Jul 1998 19:55:08 GMT Server: UserLand Frontier/5.1.2-WinNT <?xml version="1.0"?> <methodResponse> <params> <param> <value><string>South Dakota</string></value> </param> </params> </methodResponse>
9 응답 포멧 #
- 하위수준의 오류가 없다면 언제나 200 OK를 반환합니다.
- Content-Type은 text/xml입니다.
- Content-Length는 반드시 지정되어야하고 정확해야합니다.
- 응답의 본체는 단일 XML 구조체 <methodResponse>로 구성됩니다.<methodResponse>는 단 하나의 <params>를 가지며, <params>는 하나의 <value>를 담고 있는 한개의 <param>을 담고 있습니다.
- 실행실패를 의미하기 위해 <methodResponse>는 <fault>를 포함할 수도 있습니다. <fault>는 1개의 <struct>를 담고 있는 1개의 <value>로 구성되며, 이 <struct>안에는 1개의 <int>를 담고 있는 <faultCode>와 1개의 <string>을 담고 있는 <faultString>이 포함됩니다.
- <methodResponse>는 <fault>와 <params> 중 하나만 담고 있어야합니다.
10 실패응답 예제 #
HTTP/1.1 200 OK Connection: close Content-Length: 426 Content-Type: text/xml Date: Fri, 17 Jul 1998 19:55:02 GMT Server: UserLand Frontier/5.1.2-WinNT <?xml version="1.0"?> <methodResponse> <fault> <value> <struct> <member> <name>faultCode</name> <value><int>4</int></value> </member> <member> <name>faultString</name> <value><string>Too many parameters.</string></value> </member> </struct> </value> </fault> </methodResponse>
11 Copyright and disclaimer #
(c) Copyright 1998-2003 UserLand Software. All Rights Reserved.
This document and translations of it may be copied and furnished to others, and derivative works that comment on or otherwise explain it or assist in its implementation may be prepared, copied, published and distributed, in whole or in part, without restriction of any kind, provided that the above copyright notice and these paragraphs are included on all such copies and derivative works.
This document may not be modified in any way, such as by removing the copyright notice or references to UserLand or other organizations. Further, while these copyright restrictions apply to the written XML-RPC specification, no claim of ownership is made by UserLand to the protocol it describes. Any party may, for commercial or non-commercial purposes, implement this protocol without royalty or license fee to UserLand. The limited permissions granted herein are perpetual and will not be revoked by UserLand or its successors or assigns.
This document and the information contained herein is provided on an "AS IS" basis and USERLAND DISCLAIMS ALL WARRANTIES, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO ANY WARRANTY THAT THE USE OF THE INFORMATION HEREIN WILL NOT INFRINGE ANY RIGHTS OR ANY IMPLIED WARRANTIES OF MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE.









