且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

如何使用 Python 的请求将复杂类型发布到 WCF?

更新时间:2022-06-02 17:49:35

您需要在 POST body 中发送 JSON,但您将其附加到查询参数中.

You need to send JSON in the POST body, but you are attaching it to the query parameters instead.

改用data,只对外部结构进行编码:

Use data instead, and only encode the outer structure:

result=req.post(wsAddr+methodPath,
                data=json.dumps({'composite': cType}),
                headers=headers)

如果您对 cType 进行编码,您将发送一个包含另一个 JSON 编码字符串的 JSON 编码字符串,该字符串又包含您的 cType 字典.

If you encoded cType, you'd send a JSON-encoded string containing another JSON-encoded string, which in turn contains your cType dictionary.