質問をすることでしか得られない、回答やアドバイスがある。

15分調べてもわからないことは、質問しよう!

新規登録して質問してみよう
ただいま回答率
85.47%
TypeScript

TypeScriptは、マイクロソフトによって開発された フリーでオープンソースのプログラミング言語です。 TypeScriptは、JavaScriptの構文の拡張であるので、既存の JavaScriptのコードにわずかな修正を加えれば動作します。

Q&A

0回答

730閲覧

APIリクエスト時の証明書無視について

tensaikumabouzu

総合スコア45

TypeScript

TypeScriptは、マイクロソフトによって開発された フリーでオープンソースのプログラミング言語です。 TypeScriptは、JavaScriptの構文の拡張であるので、既存の JavaScriptのコードにわずかな修正を加えれば動作します。

0グッド

1クリップ

投稿2023/03/06 13:02

あるAPIを触っていて、makeDateFolder関数を実行すると、401のエラーが返却されます。
APIサーバーに関して、証明書を無視して実行するようにコードを書いているのですが、うまく行ってないです。

typescript

1process.env.NODE_TLS_REJECT_UNAUTHORIZED = "0" 2async function makeDateFolder():Promise<void> { 3 try{ 4 const cookieData = await sessionAuthenticate() 5 const config = { 6 headers : { 7 'Cookie': cookieData.sessionId, 8 'X-CSRF-Token': cookieData.csrfToken, 9 'x-isi-ifs-target-type': 'container', 10 'Referer': `https://${isilonIp}` 11 }, 12 httpsAgent: new https.Agent({ rejectUnauthorized: false, requestCert: false }) 13 } 14 await axios.put(`${defaultRequestUrl}/namespace${defaultDirectoryPath}_backup/${dateFolderName}`, config) 15 console.log(`success to make ${dateFolderName} folder`) 16 }catch(e){ 17 console.error(e) 18 }

エラー内容は下記になります。
authorizationError: 'DEPTH_ZERO_SELF_SIGNED_CERT',
をなくすために
process.env.NODE_TLS_REJECT_UNAUTHORIZED = "0"
を書いているのですが、変わらないです。
sessionAuthenticate()関数は、他のAPIでも利用しており、正常に動いていることが確定しています。
何かアドバイス頂けないでしょうか?

error

1{ [AxiosError: Request failed with status code 401] 2 message: 'Request failed with status code 401', 3 name: 'AxiosError', 4 code: 'ERR_BAD_REQUEST', 5 config: 6 { transitional: 7 { silentJSONParsing: true, 8 forcedJSONParsing: true, 9 clarifyTimeoutError: false }, 10 adapter: [Function: httpAdapter], 11 transformRequest: [ [Function: transformRequest] ], 12 transformResponse: [ [Function: transformResponse] ], 13 timeout: 0, 14 xsrfCookieName: 'XSRF-TOKEN', 15 xsrfHeaderName: 'X-XSRF-TOKEN', 16 maxContentLength: -1, 17 maxBodyLength: -1, 18 env: { FormData: [Function] }, 19 validateStatus: [Function: validateStatus], 20 headers: 21 { Accept: 'application/json, text/plain, */*', 22 'Content-Type': 'application/json', 23 'User-Agent': 'axios/0.27.2', 24 'Content-Length': 546 }, 25 method: 'put', 26 url: 27 'https://172.30.32.96:8080/namespace/ifs/zone1/share/_backup/20230306', 28 data: 29 '{"headers":{"Cookie":"isisessid=89b7aab3-2f46-4ac4-a330-c78463c31c1a","X-CSRF-Token":"f16cb2ce-8419-4107-8f06-c40ce42d29d8","x-isi-ifs-target-type":"container","Referer":"https://172.30.32.96"},"httpsAgent":{"domain":null,"_events":{},"_eventsCount":1,"defaultPort":443,"protocol":"https:","options":{"requestCert":false,"rejectUnauthorized":false,"path":null},"requests":{},"sockets":{},"freeSockets":{},"keepAliveMsecs":1000,"keepAlive":false,"maxSockets":null,"maxFreeSockets":256,"maxCachedSessions":100,"_sessionCache":{"map":{},"list":[]}}}' }, 30 request: 31 ClientRequest { 32 domain: null, 33 _events: 34 [Object: null prototype] { 35 socket: [Function], 36 abort: [Function], 37 aborted: [Function], 38 connect: [Function], 39 error: [Function], 40 timeout: [Function], 41 prefinish: [Function: requestOnPrefinish] }, 42 _eventsCount: 7, 43 _maxListeners: undefined, 44 output: [], 45 outputEncodings: [], 46 outputCallbacks: [], 47 outputSize: 0, 48 writable: true, 49 _last: true, 50 chunkedEncoding: false, 51 shouldKeepAlive: false, 52 useChunkedEncodingByDefault: true, 53 sendDate: false, 54 _removedConnection: false, 55 _removedContLen: false, 56 _removedTE: false, 57 _contentLength: null, 58 _hasBody: true, 59 _trailer: '', 60 finished: true, 61 _headerSent: true, 62 socket: 63 TLSSocket { 64 _tlsOptions: [Object], 65 _secureEstablished: true, 66 _securePending: false, 67 _newSessionPending: false, 68 _controlReleased: true, 69 _SNICallback: null, 70 servername: '172.30.32.96', 71 alpnProtocol: false, 72 authorized: false, 73 authorizationError: 'DEPTH_ZERO_SELF_SIGNED_CERT', 74 encrypted: true, 75 _events: [Object], 76 _eventsCount: 8, 77 connecting: false, 78 _hadError: false, 79 _handle: [TLSWrap], 80 _parent: null, 81 _host: null, 82 _readableState: [ReadableState], 83 readable: true, 84 domain: null, 85 _maxListeners: undefined, 86 _writableState: [WritableState], 87 writable: false, 88 allowHalfOpen: false, 89 _sockname: null, 90 _pendingData: null, 91 _pendingEncoding: '', 92 server: undefined, 93 _server: null, 94 ssl: [TLSWrap], 95 _requestCert: true, 96 _rejectUnauthorized: false, 97 parser: null, 98 _httpMessage: [Circular], 99 [Symbol(res)]: [TLSWrap], 100 [Symbol(asyncId)]: 193, 101 [Symbol(lastWriteQueueSize)]: 0, 102 [Symbol(timeout)]: null, 103 [Symbol(kBytesRead)]: 0, 104 [Symbol(kBytesWritten)]: 0, 105 [Symbol(connect-options)]: [Object] }, 106 connection: 107 TLSSocket { 108 _tlsOptions: [Object], 109 _secureEstablished: true, 110 _securePending: false, 111 _newSessionPending: false, 112 _controlReleased: true, 113 _SNICallback: null, 114 servername: '172.30.32.96', 115 alpnProtocol: false, 116 authorized: false, 117 authorizationError: 'DEPTH_ZERO_SELF_SIGNED_CERT', 118 encrypted: true, 119 _events: [Object], 120 _eventsCount: 8, 121 connecting: false, 122 _hadError: false, 123 _handle: [TLSWrap], 124 _parent: null, 125 _host: null, 126 _readableState: [ReadableState], 127 readable: true, 128 domain: null, 129 _maxListeners: undefined, 130 _writableState: [WritableState], 131 writable: false, 132 allowHalfOpen: false, 133 _sockname: null, 134 _pendingData: null, 135 _pendingEncoding: '', 136 server: undefined, 137 _server: null, 138 ssl: [TLSWrap], 139 _requestCert: true, 140 _rejectUnauthorized: false, 141 parser: null, 142 _httpMessage: [Circular], 143 [Symbol(res)]: [TLSWrap], 144 [Symbol(asyncId)]: 193, 145 [Symbol(lastWriteQueueSize)]: 0, 146 [Symbol(timeout)]: null, 147 [Symbol(kBytesRead)]: 0, 148 [Symbol(kBytesWritten)]: 0, 149 [Symbol(connect-options)]: [Object] }, 150 ーー省略 151```

気になる質問をクリップする

クリップした質問は、後からいつでもMYページで確認できます。

またクリップした質問に回答があった際、通知やメールを受け取ることができます。

バッドをするには、ログインかつ

こちらの条件を満たす必要があります。

maisumakun

2023/03/06 15:10

えっと、「本当にサーバが401を返している」という可能性は潰していますか?
guest

あなたの回答

tips

太字

斜体

打ち消し線

見出し

引用テキストの挿入

コードの挿入

リンクの挿入

リストの挿入

番号リストの挿入

表の挿入

水平線の挿入

プレビュー

まだ回答がついていません

会員登録して回答してみよう

アカウントをお持ちの方は

15分調べてもわからないことは
teratailで質問しよう!

ただいまの回答率
85.47%

質問をまとめることで
思考を整理して素早く解決

テンプレート機能で
簡単に質問をまとめる

質問する

関連した質問