[ CURL ] JSON ÇüÅ·Πoutput Ãâ·Â

   Á¶È¸ 1491   Ãßõ 0    

아래와 같이 실행하면, 의도와 바와 다르게 JSON(들여쓰기 지원))으로 출력이 되지 않습니다.   

http(s) header / body 내용을 편하게 보고자 합니다.

json_pp도 설치해도, 제대로 동작하지 않네요   


HTTP Header & Body를 모두 JSON형태로 출력하고자 합니다. <=============== !!!

   

해당 문제 해결을 위한 조언 부탁 드려 봅니다.

감사합니다.

   


   

----

 #> curl -vks --head www.nhsung.com | jq '.'

*   Trying 15.165.181.187:80...

* Connected to www.nhsung.com (15.165.181.187) port 80 (#0)

> HEAD / HTTP/1.1

> Host: www.nhsung.com

> User-Agent: curl/7.79.1

> Accept: */*

>

* Mark bundle as not supporting multiuse

< HTTP/1.1 200 OK

< Date: Sun, 28 Aug 2022 10:01:33 GMT

< Content-Type: text/html

< Content-Length: 3520

< Connection: keep-alive

< Server: nginx/1.20.0

< Last-Modified: Tue, 12 Jul 2022 01:09:57 GMT

< ETag: "62ccc9e5-dc0"

< Accept-Ranges: bytes

<

* Connection #0 to host www.nhsung.com left intact

parse error: Invalid numeric literal at line 1, column 9                                                   


ªÀº±Û Àϼö·Ï ½ÅÁßÇÏ°Ô.
Noname1 2022-08
¿äûÇÏ´Â ÁÖ¼Ò°¡ jsonÀ» Ãâ·ÂÇÏ´Â urlÀÎÁö È®ÀÎÇϽðí

curl ¿É¼ÇÀ» À߸ø »ç¿ëÇÏ°í °è½Ê´Ï´Ù.
     
Noname1 2022-08
curl -sL 'https://ip-ranges.amazonaws.com/ip-ranges.json' | jq '.'
          
¾Ë·Á ÁֽŠ¸í·É¾î Á¦´ë·Î µ¿ÀÛÇÏ´Â °ÍÀ» È®ÀÎÇÏ¿´½À´Ï´Ù.

ÀúÀÇ °æ¿ì´Â Çì´õ ¹× ¹Ùµð¸¦ µ¿½Ã¿¡ JSON ÇüÅ·ΠÃâ·ÂÇÏ°í ÇÕ´Ï´Ù.
-i ¿É¼Ç Ãß°¡¸¦ Çϸé, header°¡ json ÇüÅ°¡ ¾Æ´Ï¿©¼­ ±×·±Áö ½ÇÆÐÇÏ´Â Çö»óÀÌ ¹ß»ýÇÕ´Ï´Ù.

$ curl -sL -i 'https://ip-ranges.amazonaws.com/ip-ranges.json' | jq '.'
parse error: Invalid numeric literal at line 1, column 9
               
Noname1 2022-08
header¿Í body ÇÕÃļ­ jsonÀ¸·Î ÇÏ·Á¸é curl Ä¿¸Çµå ÀÚü·Î´Â Áö¿øÇÏÁø ¾Ê´Â°Í°°°í Á÷Á¢ ÆĽÌÇؾßÇÒ°Ì´Ï´Ù
curl Ä¿¸Çµå ¾Æ´Ñ ´Ù¸¥ ¼Ö·ç¼ÇÀ» ã¾Æº¸¼¼¿ä.


ã¾Æº¸´Ï curl 7.84 ¹öÀü ºÎÅÍ -w "%{header_json}" ¸¦ ³ÖÀ¸¸é Çì´õ¸¦ jsonÀ¸·Î Ãâ·ÂÇØÁشٰí Çϳ׿ä.
./curl-amd64 https://ip-ranges.amazonaws.com/ip-ranges.json -w '%{header_json}' | jq -s '.[1] * .[0]'

..................... jq ¾î·Æ³×¿ä
¾î¶»°Ô Æ÷¸ÅÆÃÇؾߵǴÂÁö ¸ð¸£°Ú½À´Ï´Ù
¹Ú»óÀÏ 2022-08
¿äûÇÑ URL : www.nhsung.com ÀÌ jsonÀ» ¹ÝȯÇÏÁö ¾Ê³×¿ä.
À§¿¡¼­ < Content-Type: text/html -> json typeÀ¸·Î responseÇÏ´Â URLÀ» ¿äûÇØ¾ß jq·Î Æ÷¸ÅÆÃÀÌ µÉ°Í °°³×¿ä.
     
³×.. nginx·Î ¸¸µç ±øÅë ȨÆäÀÌÁö À̱ä ÇÕ´Ï´Ù. index.html¸¸ °¡Áö°í ¿À´Ï..
2ºÐ²²¼­ Á¶¾ðÁֽŠ°ÍÀ¸·Î Åä´ë·Î, º»¹®¿¡ ÁúÀÇ ³»¿ª Ãß°¡ ÇÏ¿´½À´Ï´Ù.
     
¾Æ¾¥ 2022-08
curl -X GET www.nhsung.com -H "Content-Type: text/html" -H "Accept: application/json"

À§¿Í °°Àº ¸í·ÉÀ¸·Î ½ÇÇà½Ã ¾Æ·¡¿Í °°Àº °á°ú¸¦ È®ÀÎ °¡´ÉÇϸç, °á°ú·Î ÃßÃøÇغ¸¸é... Amazon Linux¿¡¼­ json¿¡ ´ëÇÑ ¼³Á¤ÀÌ µÇ¾î ÀÖÁö ¾ÊÀº°Í °°³×¿ä.
====================================================================================================================
Server: nginx/1.20.0
Last-Modified: Tue, 12 Jul 2022 01:09:57 GMT
ETag: "62ccc9e5-dc0"
Accept-Ranges: bytes

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN" "http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">

<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en">
    <head>
        <title>Test Page for the Nginx HTTP Server on Amazon Linux</title>
        <meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
        <style type="text/css">
            /*<![CDATA[*/
            body {
                background-color: #fff;
                color: #000;
                font-size: 0.9em;
                font-family: sans-serif,helvetica;
                margin: 0;
                padding: 0;
            }
            :link {
                color: #c00;
            }
            :visited {
                color: #c00;
            }
            a:hover {
                color: #f50;
            }
            h1 {
                text-align: center;
                margin: 0;
                padding: 0.6em 2em 0.4em;
                background-color: #294172;
                color: #fff;
                font-weight: normal;
                font-size: 1.75em;
                border-bottom: 2px solid #000;
            }
            h1 strong {
                font-weight: bold;
                font-size: 1.5em;
            }
            h2 {
                text-align: center;
                background-color: #3C6EB4;
                font-size: 1.1em;
                font-weight: bold;
                color: #fff;
                margin: 0;
                padding: 0.5em;
                border-bottom: 2px solid #294172;
            }
            hr {
                display: none;
            }
            .content {
                padding: 1em 5em;
            }
            .alert {
                border: 2px solid #000;
            }

            img {
                border: 2px solid #fff;
                padding: 2px;
                margin: 2px;
            }
            a:hover img {
                border: 2px solid #294172;
            }
            .logos {
                margin: 1em;
                text-align: center;
            }
            /*]]>*/
        </style>
    </head>

    <body>
        <h1>Welcome to <strong>nginx</strong> on Amazon Linux!</h1>

        <div class="content">
            <p>This page is used to test the proper operation of the
            <strong>nginx</strong> HTTP server after it has been
            installed. If you can read this page, it means that the
            web server installed at this site is working
            properly.</p>

            <div class="alert">
                <h2>Website Administrator</h2>
                <div class="content">
                    <p>This is the default <tt>index.html</tt> page that
                    is distributed with <strong>nginx</strong> on
                    Amazon Linux.  It is located in
                    <tt>/usr/share/nginx/html</tt>.</p>

                    <p>You should now put your content in a location of
                    your choice and edit the <tt>root</tt> configuration
                    directive in the <strong>nginx</strong>
                    configuration file
                    <tt>/etc/nginx/nginx.conf</tt>.</p>

                </div>
            </div>

            <div class="logos">
                <a href="http://nginx.net/"><img
                    src="nginx-logo.png"
                    alt="[ Powered by nginx ]"
                    width="121" height="32" /></a>
            </div>
        </div>
    </body>
</html>
====================================================================================================================


QnA
Á¦¸ñPage 349/5593
2015-12   1042517   ¹é¸Þ°¡
2014-05   4489964   Á¤ÀºÁØ1
2022-09   1101   Ãʺ¸2cpu
2022-09   1244   È­¶õ
2022-09   929   inquisitive
2022-09   917   sauoory
2022-09   897   ³ª¶ó»ç¶û
2022-09   1193   ±èÇØÁø
2022-09   713   viper9
2022-09   1113   ½Å¿ì¼·
2022-09   688   ±èÁ¦¿¬
2022-09   944   galaxyfamily
2022-09   1273   Ulmo
2022-09   1047   ½Ã¿ÀÈÅÀÌ
2022-09   1510   niet38h
2022-09   3712   È­¶õ
2022-09   1262   ³ª¶ó»ç¶û
2022-09   1651   Elusive4245
2022-09   2152   ºí·ç¸ð¼Ç
2022-09   1583   ÀǷӰԻ츮¶ó
2022-09   1174   ǪÀÌÀ×À×
2022-09   1721   Çï·Î¿ì