api-testing/pkg/generator/testdata/expected_javascript_body_re...

43 lines
1.4 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.
*/
async function makeRequest() {
const headers = new Headers();
headers.append("User-Agent", "atest");
const requestOptions = {
method: "GET",
headers: headers,
redirect: "follow"
};
console.log('the body is ignored because this is a GET request')
/*
let body = `{"key": "value"}`;
requestOptions.body = body;
*/
try {
const response = await fetch("https://www.baidu.com", requestOptions);
if (response.ok) { // Check if HTTP status code is 200/OK
const text = await response.text();
console.log(text);
} else {
throw new Error('Network response was not ok. Status code: ' + response.status);
}
} catch (error) {
console.error('Fetch error:', error);
}
}
makeRequest();