前提・実現したいこと
Google Apps Scriptで航空会社の運航状況のサイトをスクレイピングしたいと思ってます。
URL https://api.cathaypacific.com/flightinformation/flight-status/olss-flight-status/v4.0/flightStatusByFlightNumber
必要な情報をPOSTしましたが、エラーが返されました。
発生している問題・エラーメッセージ
{"timestamp":"2019-08-14 14:22:34","status":400,"error":"Bad Request","exception":"org.springframework.http.converter.HttpMessageNotReadableException","message":"Could not read document: Unrecognized token 'travelDate': was expecting 'null', 'true', 'false' or NaN\n at [Source: java.io.PushbackInputStream@11423404; line: 1, column: 12]; nested exception is com.fasterxml.jackson.core.JsonParseException: Unrecognized token 'travelDate': was expecting 'null', 'true', 'false' or NaN\n at [Source: java.io.PushbackInputStream@11423404; line: 1, column: 12]","path":"/olss-flight-status/v4.0/flightStatusByFlightNumber"}
該当のソースコード
function POST(){
var payload =
{
"travelDate" : "2019-08-13",
"carrierCode":"",
"flightNumber":"208",
"locale":"ja_JP",
"departureArrival":"D"
};
var postheader = {
"useragent":"Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/76.0.3809.100 Safari/537.36",
"accept":"application/json, text/plain, /"
}
var options =
{
"method" : "post",
"headers": postheader,
"payload" : payload,
"muteHttpExceptions" : true,
"contentType":"application/json;charset=UTF-8"
};
var res = UrlFetchApp.fetch("https://api.cathaypacific.com/flightinformation/flight-status/olss-flight-status/v4.0/flightStatusByFlightNumber", options);
Logger.log(res.getContentText())
}
回答2件
あなたの回答
tips
プレビュー
バッドをするには、ログインかつ
こちらの条件を満たす必要があります。