【发布时间】:2017-08-17 04:54:22
【问题描述】:
我在 python 中做 Python 客户端 HTTPSConnection.request('POST', url, data, headers)。 数据为b'1502944466046',即请求正文
调试打印显示:
send: b'POST /path/to/someresource HTTP/1.1\r\nHost: 172.1.2.3\r\nAccept-Encoding: identity\r\nContent-Length: 13\r\nContent-Type: application/ xml;charset=UTF-8\r\nAccept: application/xml\r\nAuthorization: Basic encodeduserPwd==\r\n\r\n'
发送:b'1502944466046'
在 Java 服务器上,我得到 org.xmlpull.v1.XmlPullParserException: only whitespace content allowed before start tag and not 1 (position: START_DOCUMENT seen 1...@1:1)
POST 的数据只是下面派生的“数据”变量,如下所示:
name = str(int(round(time.time() * 1000))) # time in millisec used
data = name.encode('utf-8')
Java REST 控制器有一个方法:
@RequestMapping(value=sameurlaspythonurlabove, method=RequestMethod.POST)
@ResponseStatus(HttpStatus.CREATED)
public void createMyObject(@RequestBody String name)
由于上述异常,该方法未命中。
正文不是 XML,但我认为服务器正试图从上面的错误中解析 XML。
如果我设置 Content-type = 'text/plain',那么服务器会给出 org.springframework.web.HttpMediaTypeNotSupportedException: Content type 'text/plain;charset=UTF-8' not supported
任何想法如何规避?
【问题讨论】:
标签: java python xml http-post xstream