2017-12-18 10 views
1

Linux 셸 스크립트에서 CURL을 통해 멀티 파트 양식 POST를 보내고 있습니다. 이 요청은 우편 배달에서 잘 작동하지만 CURL에서 그것은 실패 : 다음CURL multipart form post - 보내기가 끝나기 전에 HTTP 오류가 발생합니다.

Internal Server Error 

HTTP error before end of send, stop sending 

심지어 직접 우편 배달에서 리눅스 쉘 코드에 대한 컬을 복사하고 쉘 스크립트에 붙여, 그래서해야 우편 배달부가하는 것과 똑같은 요청입니다. 여기

curl --request POST \ 
    --no-alpn \ 
    --url https://XXXXXXXXXXX/api/v1.0/XXXXX/XXXXXX/XXXXX \ 
    --header 'accept: text/plain' \ 
    --header 'cache-control: no-cache' \ 
    --header 'content-type: multipart/form-data; boundary=----WebKitFormBoundary7MA4YWxkTrZu0gW' \ 
    --header 'sessionid: $session_id' \ 
    --form filename=XXXXXX.zip \ 
    --form XXXXXX=XXXXXX \ 
    --form [email protected]$file_path \ 
    --trace-ascii /dev/stdout || exit $? 
} 

그리고

은 --trace-ASCII의 로그입니다 :

https://XXXXXXXXXXXXXXXXX/api/v1.0/XXXXXX/XXXXX/XXXXXXXXX 
Note: Unnecessary use of -X or --request, POST is already inferred. 
    % Total % Received % Xferd Average Speed Time Time  Time Current 
           Dload Upload Total Spent Left Speed 

    0  0 0  0 0  0  0  0 --:--:-- --:--:-- --:--:--  0== Info: Trying XXX.XXX.XXX.XXXX... 
== Info: Connected to XXXXXXXXXXXXXXXX.com (XX.XX.XX.XX) port 443 (#0) 
== Info: found 148 certificates in /etc/ssl/certs/ca-certificates.crt 
== Info: found 592 certificates in /etc/ssl/certs 
== Info: SSL connection using TLS1.2/ECDHE_RSA_AES_128_GCM_SHA256 
== Info:  server certificate verification OK 
== Info:  server certificate status verification SKIPPED 
== Info:  common name: *.XXXXXX.com (matched) 
== Info:  server certificate expiration date OK 
== Info:  server certificate activation date OK 
== Info:  certificate public key: RSA 
== Info:  certificate version: #3 
== Info:  subject: OU=Domain Control Validated,CN=*.XXXXXX.com 
== Info:  start date: Mon, 15 Aug 2016 08:23:38 GMT 
== Info:  expire date: Thu, 15 Aug 2019 08:23:38 GMT 
== Info:  issuer: C=US,ST=Arizona,L=Scottsdale,O=GoDaddy.com\, Inc.,OU=http://certs.godaddy.com/repository/,CN=Go Daddy Secure Certificate Authority - G2 
== Info:  compression: NULL 
=> Send header, 363 bytes (0x16b) 
0000: POST /XXXXX/api/v1.0/XXXXXX/upload/XXXXXX HTTP/1.1 
003b: Host: XXXXXX.XXXXXXX.com 
0059: User-Agent: curl/7.47.0 
0072: accept: text/plain 
0086: cache-control: no-cache 
009f: sessionid: $session_id 
00b7: Content-Length: 1639 
00cd: Expect: 100-continue 
00e3: content-type: multipart/form-data; boundary=----WebKitFormBounda 
0123: ry7MA4YWxkTrZu0gW; boundary=------------------------b059847fb557 
0163: a899 
0169: 
<= Recv header, 23 bytes (0x17) 
0000: HTTP/1.1 100 Continue 
=> Send data, 387 bytes (0x183) 
0000: --------------------------b059847fb557a899 
002c: Content-Disposition: form-data; name="filename" 
005d: 
005f: xxxxxxxxxx.zip 
006b: --------------------------b059847fb557a899 
0097: Content-Disposition: form-data; name="XXXXXXXXXXX" 
00cc: 
00ce: XXXXXXXXXXXXXXXXXXXX 
00ea: --------------------------b059847fb557a899 
0116: Content-Disposition: form-data; name="file"; filename="XXXXXX.zip 
0156: " 
0159: Content-Type: application/octet-stream 
0181: 
=> Send data, 1204 bytes (0x4b4) 
0000: PK........r~.K..D!....p.......output/XXXXXXX.XXXXX.....7Z..7Zux... 
0040: ............{[email protected]!`.9. F..Eh+.......JA..W.2.V...A.%>... #Q1 
0080: T.....{Nb.]&..1.3M|.........w..z.]8..I.I>.....n?...\hM/.h..?oy^. 
00c0: ..... ..:.>J..Q...N...*A...l`...."[email protected]'........d..._.....L 
0100: .].......z....N6.B......Y5t...Zd.V...}..l...........EC..$..e...W 
0140: .V`.lV...p..d._.....S...............d`.l..}.....f[...{....`....M 
0180: .....kN..[.4.2w.9.bN....q.8.'.K.......'..~........sI.....K...s. 
01c0: ...U.'..d,.......>......T.5....|.$,)o'bIy{...pN.....K.o..[..cWp. 
0200: [email protected]/.F..0....=4.......d..#{K$..#.^=....... 
0240: *....Bi...i....8j!T......|.Ld...x....>......A...|.I.}>.....Yt=.. 
0280: ..Tp.q...O&.. .....Ac..V....a......f.G...!x.f.i.gu}.2i.4....NK.. 
02c0: .G;..k~......=*....g..c#..c.M.oW........-...vW.~#u...#....cz.bu= 
0300: .."Bs.js\.z.1.....&|.MV..<a"4...IqRO.kKC.v.Gz.....].G.\.|...:om 
0340: .C.v5G..X].kw..\....R/.........C.X].5<.B.\'....z.O|@.v.P\...... 
0380: ^...f~........9....YG~fum}....^,K.......F.vmIl....hI."h.FM.....f 
03c0: ....Z...`um.}E...1;......_....yF.xV...BDh...U..z...*.o.`O..V.W.6 
0400: ..kf.n...*.{..].].c~.w~K......4I.k.Y.....r.wV.................F 
0440: .v..O..OPK..........r~.K..D!....p.....................output/xxxxxxx 
.mldUT.....7Zux.............PK..........V...H..... 
=> Send data, 48 bytes (0x30) 
0000: 
0002: --------------------------b059847fb557a899-- 
<= Recv header, 36 bytes (0x24) 
0000: HTTP/1.1 500 Internal Server Error 
<= Recv header, 15 bytes (0xf) 
0000: Server: nginx 
<= Recv header, 37 bytes (0x25) 
0000: Date: Mon, 18 Dec 2017 15:15:56 GMT 
<= Recv header, 26 bytes (0x1a) 
0000: Content-Type: text/plain 
<= Recv header, 28 bytes (0x1c) 
0000: Transfer-Encoding: chunked 
<= Recv header, 24 bytes (0x18) 
0000: Connection: keep-alive 

100 1639 0  0 100 1639  0 2269 --:--:-- --:--:-- --:--:-- 2266<= Recv header, 29 bytes (0x1d) 
0000: X-FRAME-OPTIONS: SAMEORIGIN 
<= Recv header, 83 bytes (0x53) 
0000: Set-Cookie: JSESSIONID=XXXXXXXXXXXXXXXXXXXXXXXX; Path=/; 
0040: Secure; HttpOnly 
== Info: HTTP error before end of send, stop sending 
<= Recv header, 2 bytes (0x2) 
0000: 
<= Recv data, 106 bytes (0x6a) 
0000: 64 
0004: <ErrorResponse><key/><localizedMessage/><httpError>Internal Serv 
0044: er Error</httpError></ErrorResponse> 
<= Recv data, 5 bytes (0x5) 
0000: 0 
0003: 

내가 CURL 명령은 도커 컨테이너에서 실행되고 있음을 추가해야합니다 여기

는 명령입니다.

+0

설명이 프로그래밍 방식은 무엇입니까? 리눅스 쉘 스크립트이기 때문에? YML 내에 내장 된 Python 코드에 의해 호출됩니다. –

+0

"... 스크립트에"추가하는 것은 매력적이지 않습니다. 문제가 [Minimal, Complete, Verifiable example] (http://stackoverflow.com/help/mcve)로 줄어들면 cURL 명령을 실행하는 방법에 관한 질문. 또는 서버가 충돌하는 이유. 명백한 무언가를 놓치고 있다면 사과드립니다. – jww

답변

0

을 참조 문제는 큰 따옴표로 둘러싸여 세션 ID를 보내는 것을, 그래서 서버는 숫자로 구문 분석하는 데 실패에서 예외가 발생했습니다 및 요청을 거부했다. 서버 로그를 파악하여이를 파악해야했습니다. 이렇게하면

someJson | jq '.sessionId' 

은, JQ는 큰 따옴표로 결과를 반환합니다

이유 세션 ID는 내가 사용하는 세션 ID를 설정하고, 코드로 인해 이전에 있었다 따옴표로했다. 큰 따옴표없이 값을 얻으려면 다음을 사용하십시오.

someJson | jq -r '.sessionId' 
0

컬 명령에 문제가 있습니다. $session_id에 작은 따옴표가 있기 때문에 변수가 평가되지 않습니다.

"따옴표"모든 확장 공간/메타 문자를 포함하고 그 모든 문자 : "$var", "$(command "$var")", "${array[@]}", "a & b"을. 코드 또는 리터럴 $'s: 'Costs $5 US', ssh host 'echo "$HOSTNAME"''single quotes'을 사용하십시오. 내 특정 경우
http://mywiki.wooledge.org/Quotes
http://mywiki.wooledge.org/Arguments
http://wiki.bash-hackers.org/syntax/words