実現したいこと
GAS 経由で InterFAX REST サービスを呼び出したい
発生している問題・分からないこと
GAS 経由で InterFAX REST サービスを呼び出したいのですが、なぜか 401/HTTP になってしまいます。
手元で curl を使って呼び出す事はできますので、id/password の問題ではありません。
javascript の実行もブラウザでは無く google 環境のようで、実際に通信上で何が起きているのか調べる方法が (少なくとも私には) 解りません。
エラーメッセージ
error
1401/HTTP が返されます
該当のソースコード
javascript
1function sendInterfaxFax() { 2 const USERNAME = '***'; 3 const PASSWORD = '***'; 4 5 const url = 'https://rest.interfax.net/outbound/faxes?limit=1'; 6 7 const options = { 8 'method': 'GET', 9 'headers': { 10 'Authorization': 'Basic ' + Utilities.base64Encode(USERNAME + ':' + PASSWORD, Utilities.Charset.UTF_8) 11 }, 12 'cache': 'no-store', 13 'muteHttpExceptions': true 14 }; 15 16 try { 17 const response = UrlFetchApp.fetch(url, options); 18 const responseCode = response.getResponseCode(); 19 const responseBody = response.getContentText(); 20 21 if (responseCode >= 200 && responseCode < 300) { 22 Logger.log('Request Success: ' + responseBody); 23 } else { 24 Logger.log('error status: ' + responseCode); 25 Logger.log('error detail: ' + responseBody); 26 } 27 } catch (e) { 28 Logger.log('exception: ' + e.message); 29 } 30} 31 32sendInterfaxFax();
試したこと・調べたこと
- teratailやGoogle等で検索した
- ソースコードを自分なりに変更した
- 知人に聞いた
- その他
上記の詳細・結果
id/password の間違いを指摘する意見ばかりですが、curl の場合でも GAS の場合でもAuthorization ヘッダの値が同じである事は確認済みです。
curl の場合は実施環境で、GASの場合はダミーのサーバを立ててネットワークをキャプチャーし、
SSLKEYLOGFILE を使って通信を複合化して厳密に値が一致する事を確認しています。
補足
特になし