urllib.request我使用Python 3发送我的 JSON 。
data = {"a": "1"}
req = urllib.request.Request('https://example.com', data=json.dumps(data).encode('utf8'), headers={'Content-Type': 'application/json'})
urllib.request.urlopen(req)
问题是data=json.dumps(data).encode('utf8')它转换{"a": "1"}为带有b前缀的相同字符串b'{"a": "1"}'。
我知道在 python 中我可以decode('utf8)用来删除b前缀,但我需要能够在服务器端执行此操作,因为 python 3 强制您发送字节流数据。
我使用 php 作为服务器端代码。
我尝试使用utf8_decode(),但它没有做任何事情。
如何删除b服务器端代码上的前缀?