0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 3 years have passed since last update.

curlでXML-RPCサービスの死活監視(XMLファイル読み込みでなくコマンドラインで完結したい)

Posted at

XML-RPCサーバの死活監視が必要になり、例のごとくcurlを使ってシンプルに実現したい。

ググるとXMLファイルを読み込む方法が散見されるが、このためにファイルを追加するのは避けたいし、死活監視用に作成したメソッド(alive)は引数を持たないシンプルな実装。

以下のようにシンプルなXMLなのでコマンドラインに直接書きたい。
(一目瞭然ですが、メソッド名は要素内の値で指定できます)

<?xml version='1.0'?>
<methodCall>
  <methodName>alive</methodName>
  <params></params>
</methodCall>

結果として、以下でいけた。以下はExampleServiceのliveメソッドを実行している。

curl -X POST -d '<?xml version='\''1.0'\''?><methodCall><methodName>alive</methodName><params></params></methodCall>' http(s)://<domain>:<port>/ExampleService.php

ポイントは以下の2つ

  • -X POST・・・XML-RPCはPOSTメソッドなのでPOSTを指定
  • '\''・・・シングルクォートのエスケープ ★後で気づいたけどダブルクォートだとエスケープ不要

あとは、指定しないでも問題ありませんでしたが、プロトコルがHTTP/XMLであることを明示しておきたい場合は、ヘッダーオプションでtext/xmlを指定するとよいかもしれません。

-H 'Content-type: text/xml'
0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?