我只是想发送一个请求,并读出一个ogc sos服务器的答案。为什么服务器在POST方法请求后使用GET进行响应?
发送的请求:
connection = new URL(url).openConnection();
connection.setDoOutput(true);
connection.setDoInput(true);
connection.setRequestProperty("Accept-Charset", charset);
connection.setRequestProperty("Content-Type", "application/x-www-form-urlencoded; charset="+charset);
connection.connect();
读出响应:
output = connection.getOutputStream();
output.write(query.getBytes(charset));
input = new URL(url).openStream();
Reader reader = new InputStreamReader(input);
BufferedReader bufferedReader = new BufferedReader(reader);
StringBuilder response = new StringBuilder();
String line = null;
while((line = bufferedReader.readLine()) != null)
response.append(line+"\n");
bufferedReader.close();
output.close();
的服务器的响应是:
<?xml version="1.0" encoding="UTF-8"?>
<ows:ExceptionReport xmlns:ows="http://www.opengis.net/ows/1.1"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" version="1.0.0"
xsi:schemaLocation="http://schemas.opengis.net/ows/1.1.0/owsExceptionReport.xsd">
<ows:Exception exceptionCode="InvalidRequest" locator="REQUEST">
<ows:ExceptionText>The GET request null is not supported by this SOS.</ows:ExceptionText>
</ows:Exception>
</ows:ExceptionReport>
格式是一种特殊的SOS型,但主要的消息是“GET请求空” 所以它看起来像服务器通过GET方法读取请求。
我不是那么坚定的网络,但据我了解,我确保通过setDoOutput(true);
使用POST方法,不是吗?
当我得到任何答案时,我知道有一个联系,但可能是有头的东西是错的?是否有必要在任何情况下发送它?
所以我的问题是什么可能是什么使我或服务器混淆了http方法?
我想我错过了java网络处理。
对所有帮助感到高兴。
我不确定这个确切的服务,但这看起来像一个SOAP服务。如果这是真的,则可能期望所有请求都是GET请求。尝试不使用setDoOutput(true)。如果这不起作用,我发现在命令行上使用curl可以快速排除第三方服务的故障。 –
我不确定SOAP,但是是sos是基于xml的数据交换protokoll。没有setDoOuput(true),我得到一个“java.net.ProtocolException:无法写入URLConnection ...”异常。我一直在寻找cURL,但没有经验,似乎相当奢侈,因为win会通过丢失dll等来强调我。在使用cmd的win中是否有类似的功能。 – user972851