Android 用のhttp://hc.apache.org/httpcomponents-core-ga/httpcore/examples/org/apache/http/examples/ElementalHttpServer.javaを使用しています。
次のコードを使用して応答を設定します。
HttpResponse getResponse = new BasicHttpResponse(HttpVersion.HTTP_1_1, 404, "Not Found");
getResponse.setEntity(new StringEntity(new String("The requested resource " + target + " could not be found due to mismatch!!")));
conn.sendResponseHeader(getResponse);
conn.sendResponseEntity(getResponse);
Mozilla ポスターまたはブラウザーでの私の応答には、ヘッダー 404 と応答本文があります。
The requested resource could not be found due to mismatch!!HTTP/1.1 200 OK
HTTP ボディ文字列のみを取得するにはどうすればよいですか? 応答で HTTP/1.1 200 OK が返されるのはなぜですか。私は自分のコードでこれを設定しません。どんな助けでも大歓迎です。