47 lines
1.6 KiB
Plaintext
47 lines
1.6 KiB
Plaintext
/*
|
|
Copyright 2024 API Testing Authors.
|
|
Licensed under the Apache License, Version 2.0 (the "License");
|
|
you may not use this file except in compliance with the License.
|
|
You may obtain a copy of the License at
|
|
http://www.apache.org/licenses/LICENSE-2.0
|
|
Unless required by applicable law or agreed to in writing, software
|
|
distributed under the License is distributed on an "AS IS" BASIS,
|
|
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
See the License for the specific language governing permissions and
|
|
limitations under the License.
|
|
*/
|
|
import java.io.BufferedReader;
|
|
import java.io.InputStreamReader;
|
|
import java.net.HttpURLConnection;
|
|
import java.net.URL;
|
|
import java.net.URLEncoder;
|
|
|
|
public class Main {
|
|
public static void main(String[] args) throws Exception {
|
|
String body = """
|
|
""";
|
|
byte[] postDataBytes = body.getBytes("UTF-8");
|
|
|
|
URL url = new URL("https://www.baidu.com");
|
|
HttpURLConnection conn = (HttpURLConnection) url.openConnection();
|
|
conn.setRequestMethod("GET");
|
|
conn.setRequestProperty("User-Agent", "atest");
|
|
|
|
conn.setDoOutput(true);
|
|
|
|
BufferedReader reader = new BufferedReader(new InputStreamReader(conn.getInputStream(), "UTF-8"));
|
|
StringBuilder response = new StringBuilder();
|
|
String line;
|
|
while ((line = reader.readLine()) != null) {
|
|
response.append(line);
|
|
}
|
|
reader.close();
|
|
|
|
System.out.println(response);
|
|
|
|
if (conn.getResponseCode() != HttpURLConnection.HTTP_OK) {
|
|
throw new RuntimeException("status code is not 200");
|
|
}
|
|
}
|
|
}
|