我遇到了一些我似乎无法修复的错误......这是示例代码,所以我很困惑发生了什么。错误被注释到它们出现的行的一侧。
import java.io.DataInputStream;
import java.io.DataOutputStream;
import java.net.URL;
import java.net.URLConnection;
import java.net.URLEncoder;
public class Connect {
URL url;
URLConnection urlConnection;
DataOutputStream outStream;
DataInputStream inStream;
// Build request body
String body = "fname=" + URLEncoder.encode("Atli", "UTF-8"); //Syntax error on token ";", { expected after this token
// Create connection
url = new URL("http://192.168.1.68/test/POST/post.php");
urlConnection = url.openConnection();
((HttpURLConnection)urlConnection).setRequestMethod("POST");
urlConnection.setDoInput(true);
urlConnection.setDoOutput(true);
urlConnection.setUseCaches(false);
urlConnection.setRequestProperty("Content-Type", "application/x-www-form-urlencoded");
urlConnection.setRequestProperty("Content-Length", ""+ body.length());
// Create I/O streams
outStream = new DataOutputStream(urlConnection.getOutputStream());
inStream = new DataInputStream(urlConnection.getInputStream());
// Send request
outStream.writeBytes(body);
outStream.flush();
outStream.close();
// Get Response
// - For debugging purposes only!
String buffer;
while((buffer = inStream.readLine()) != null) {
System.out.println(buffer);
}
// Close I/O streams
inStream.close();
outStream.close();
}
给出错误:
Syntax error, insert "}" to complete ClassBody
有人看到我没有看到的明显的东西吗?
附带说明一下,如果 php 在运行此类时回显 html 代码,java 是否能够理解 html 代码?