0
를 사용하여 나는이 PHP 코드를 다른 사이트로 나를 리디렉션 사이트가있을 때 리디렉션 :HttpClient를 POST 방법
<?php
header("Location: new.php?id=".$_POST["id"]."&test=".rand(5,15));
echo "35";
?>
-new.php
<?php
echo "ID: ".$_GET["id"]."| TEST: ".$_GET["test"];
?>
을 내가 POST 요청을 보내려고하는 경우 HTTPClient를 사용하면 사이트가 다른 사이트로 리디렉션되지 않습니다 (게시물 요청의 응답은 35입니다). Get 요청을 보낼 때 완벽하게 작동합니다. 요청의 응답은 ID : | TEST : 13
-http.java
public class Http {
public static void main(String[] args) {
HttpResponse response;
CloseableHttpClient client = HttpClients.createDefault();
HttpPost post = new HttpPost("http://localhost/test.php");
try {
List<NameValuePair> nameValuePairs = new ArrayList<NameValuePair>(1);
nameValuePairs.add(new BasicNameValuePair("id","55"));
post.setEntity(new UrlEncodedFormEntity(nameValuePairs));
response = client.execute(post);
BufferedReader rd = new BufferedReader(new InputStreamReader(
response.getEntity().getContent()));
String line = "";
while ((line = rd.readLine()) != null) {
System.out.println(line);
}
} catch (IOException e) {
e.printStackTrace();
}
try {
HttpGet get = new HttpGet("http://localhost/test.php");
response = client.execute(get);
BufferedReader rd = new BufferedReader(new InputStreamReader(
response.getEntity().getContent()));
String line = "";
while ((line = rd.readLine()) != null) {
System.out.println(line);
}
} catch (IOException e) {
e.printStackTrace();
}
}
}