网络请求
HTTP 请求
发送 GET 请求
typescript
import http from '@ohos.net.http'
// 创建请求
let httpRequest = http.createHttp()
httpRequest.request(
'https://api.example.com/data',
{
method: http.RequestMethod.GET,
header: {
'Content-Type': 'application/json'
}
},
(err, data) => {
if (!err) {
console.log('Response: ' + data.result)
} else {
console.log('Error: ' + JSON.stringify(err))
}
httpRequest.destroy()
}
)(内容继续...)