当我从JSP发送请求时,我使用此代码
pageEncoding="UTF-8"%>
Insert title hereRusca
выыававыавыавыавфыа
выыававыавыавыавфыа
выыававыавыавыавфыа
выыававыавыавыавфыа
并且回应是正确的,以便我看到我的参数值。但是,当我从Java发送我没有得到正确的答复。我认为这些参数没有正确发送。这是我的Java代码:
String urlParameters = "t=выыававыавыавыавфыа&l=a";
String request = "http://translate.intelsoft.az";
URL url = null;
try {
url = new URL(request);
} catch (MalformedURLException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
HttpURLConnection connection = null;
try {
connection = (HttpURLConnection) url.openConnection();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
connection.setDoOutput(true);
connection.setDoInput(true);
connection.setInstanceFollowRedirects(false);
try {
connection.setRequestMethod("POST");
} catch (ProtocolException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
connection.setRequestProperty("Content-Type", "text/html");
connection.setRequestProperty("charset", "utf-8");
connection.setRequestProperty("Content-Length", "" + Integer.toString(urlParameters.getBytes().length));
connection.setUseCaches (false);
DataOutputStream wr;
try {
wr = new DataOutputStream(connection.getOutputStream ());
wr.writeBytes(urlParameters);
wr.flush();
BufferedReader rd = new BufferedReader(new InputStreamReader(connection.getInputStream()));
String line;
while ((line = rd.readLine()) != null) {
System.out.println(line);
}
wr.close();
connection.disconnect();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}这里有什么问题?