我想要什么?
我正在使用HttpUrlConnection库开发一个Java应用程序来发送POST并从站点返回响应。
发生了什么事?
代码不显示语法错误,但是当我执行它时,它会打印消息“propertyValue:false”,即使我没有输出任何命令来打印任何内容。
我需要什么?
我需要知道这个错误在哪里(propertyValue:false),因为正如我所说,它并没有表现出它有错误。 源:
import java.util.*;
import java.io.*;
import java.net.*;
public class Main
{
public static void main(String[] args) throws IOException
{
String target = "http://google.com";
String parameters = "contentOfPost";
URL url = new URL(target);
HttpURLConnection conn = (HttpURLConnection)url.openConnection();
try{
conn.setRequestMethod("POST");
conn.setRequestProperty("Content-Type","application/x-www-form-urlencoded");
conn.setRequestProperty("Content-Length", parameters + Integer.toString(parameters.getBytes().length));
conn.setRequestProperty("Content-Language", "pt-BR");
conn.setRequestProperty("Referer", "https://www.google.com");
conn.setUseCaches(false);
conn.setDoInput(true);
conn.setDoOutput(true);
DataOutputStream wr = new DataOutputStream(conn.getOutputStream());
wr.writeBytes(parameters);
wr.flush();
wr.close();
InputStream in = conn.getInputStream();
BufferedReader rd = new BufferedReader(new InputStreamReader(in));
String line=null;
StringBuffer response = new StringBuffer();
while((line = rd.readLine()) != null) {
response.append(line);
response.append('\r');
}
rd.close();
} catch (IOException e){}
}
}
Out:propertyValue:false