You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

自定义Ejabberd IQ模块发送请求报400错误的技术求助

Why You're Seeing the 400 "Missing attribute 'id'" Error

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 id can 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_test module, and your process_sm_iq function will generate the expected "Hello World of Testing" response.

Quick Additional Notes

  • Most XMPP clients automatically include the jabber:client namespace 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

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.05.29 08:16:40