我有一个servlet如下。
public void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException
{
BufferedReader br = new BufferedReader(new InputStreamReader(request.getInputStream()));
try {
String requestLine = br.readLine(); // getting null
....
我从我的客户端调用servlet,如下所示。
HttpURLConnection httpConnection = null;
PrintWriter pwr = null;
ObjectInputStream ois = null;
try
{
String serverURL = "http://localhost:8080/app/servlet1?id=2";
httpConnection = (HttpURLConnection)(new URL(serverURL).openConnection()); //opening the connection
httpConnection.setRequestMethod("POST");
httpConnection.setDoInput(true);
httpConnection.setDoOutput(true);
httpConnection.setUseCaches(false);
pwr = new PrintWriter(httpConnection.getOutputStream());
pwr.println("inputValString");
pwr.flush();
//getting the streams
ois = new ObjectInputStream(httpConnection.getInputStream());
...
但是,当我运行客户端代码时,我总是在servlet中将requestLine
视为null。