自定义Ejabberd IQ模块发送请求报400错误的技术求助
The error message spells out the exact issue—XMPP core protocol (RFC 6120) requires every IQ stanza to include an id attribute. This id is non-negotiable because IQ stanzas operate on a strict request-response model: the client sends a request with a unique id, and the server uses the same id in its response so the client can match it to the original request.
Ejabberd's core XMPP parser enforces this rule before your custom mod_iq_test module even gets to process the IQ. That means your process_sm_iq function isn't being triggered here—validation fails early in the pipeline.
Fix: Add the id Attribute to Your IQ Request
Your original IQ request is missing the mandatory id field. Here's the corrected version:
<iq type='get' id='test_req_001'> <query xmlns='http://jabber.org/protocol/test'/> </iq> <r xmlns="urn:xmpp:sm:3"/>
- The
idcan be any unique string (like a sequential number, UUID, or custom label) as long as it's unique per active client session for ongoing requests. - Once you add this attribute, ejabberd will pass the IQ to your
mod_iq_testmodule, and yourprocess_sm_iqfunction will generate the expected "Hello World of Testing" response.
Quick Additional Notes
- Most XMPP clients automatically include the
jabber:clientnamespace for client-to-server requests, but if you're constructing stanzas manually, ensure the IQ is properly qualified (though this isn't the issue here). - The stream management tag
<r xmlns="urn:xmpp:sm:3"/>is independent of the IQ validation, so you can leave that part unchanged.
内容的提问来源于stack exchange,提问作者No_Rulz

