Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/java/364.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java请求仅在_Java_Http_Post_Request - Fatal编程技术网

Java请求仅在

Java请求仅在,java,http,post,request,Java,Http,Post,Request,这是我的代码: String httpURL = "http://codespeed_server:8000/result/add/"; URL myurl = new URL(httpURL); HttpURLConnection con = (HttpURLConnection) myurl.openConnection(); con.setDoOutput(true); DataOutputStream output = new DataOutputStream(con.getOutput

这是我的代码:

String httpURL = "http://codespeed_server:8000/result/add/";
URL myurl = new URL(httpURL);
HttpURLConnection con = (HttpURLConnection) myurl.openConnection();
con.setDoOutput(true);
DataOutputStream output = new DataOutputStream(con.getOutputStream());
output.writeBytes(query);
有人能告诉我为什么只有在我找到它的时候它才会起作用:

con.getResponseCode();

??当我调用getResponseCode()时,服务器仅获取新条目。这是正常的行为吗?还是服务器端问题?

在调用
getResponse*
getInputStream
方法(或需要响应数据的其他方法)之一之前,
URLConnection
不会建立连接(或
connect()
).

在调用
getResponse*
getInputStream
方法之一(或需要响应数据的其他方法)之前,
URLConnection
不会建立连接。

如果取出
con.getResponseCode()
,会发生什么?显示您在
writeBytes()
之后执行的操作。出于兴趣,如果您随后调用
output.close()
output.flush()
,它是否会被写入?如果您取出
con.getResponseCode()
,会发生什么?显示您在
writeBytes()之后执行的操作。
。出于兴趣,如果您在之后调用
output.close()
output.flush()
,它是否会被写入?