반응형
curl에 대한 요청 헤더를 어떻게 설정합니까?
curl
요청 에 대해 헤더에 여러 값을 전달하려면 어떻게 합니까?
-H
매개 변수를 여러 번 사용하십시오 .
curl -H "Accept-Charset: utf-8" -H "Content-Type: application/x-www-form-urlencoded" http://www.some-domain.com
때로는 헤더를 변경하는 것만으로는 충분하지 않으며 일부 사이트는 리퍼러도 확인합니다.
curl -v \
-H 'Host: restapi.some-site.com' \
-H 'Connection: keep-alive' \
-H 'Accept: text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8' \
-H 'Accept-Language: en-GB,en-US;q=0.8,en;q=0.6' \
-e localhost \
-A 'Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/29.0.1547.65 Safari/537.36' \
'http://restapi.some-site.com/getsomething?argument=value&argument2=value'
이 예에서 참조 자 (-e 또는 --referer curl)는 'localhost'입니다.
curl 요청에서 여러 헤더를 전달하려면 단순히 curl 명령을 추가 -H
하거나 추가 --header
하십시오.
예
//Simplified
$ curl -v -H 'header1:val' -H 'header2:val' URL
//Explanatory
$ curl -v -H 'Connection: keep-alive' -H 'Content-Type: application/json' http://www.example.com
더 나아 가기
User-Agent , Cookie , Host 와 같은 표준 HTTP 헤더 필드의 경우 실제로이를 설정하는 다른 방법이 있습니다. curl 명령은 다음 헤더 필드 설정을위한 지정된 옵션을 제공합니다.
- -A (또는 --user-agent) : "User-Agent"필드를 설정하십시오.
- -b (또는 --cookie) : "쿠키"필드를 설정하십시오.
- -e (또는 --referer) : "Referer"필드를 설정하십시오.
- -H (또는 --header) : "Header"필드 설정
예를 들어 다음 두 명령은 동일합니다. 둘 다 HTTP 헤더에서 "User-Agent"문자열을 변경합니다.
$ curl -v -H "Content-Type: application/json" -H "User-Agent: UserAgentString" http://www.example.com
$ curl -v -H "Content-Type: application/json" -A "UserAgentString" http://www.example.com
참고 URL : https://stackoverflow.com/questions/4212503/how-can-i-set-the-request-header-for-curl
반응형
'Programming' 카테고리의 다른 글
AngularJS는 jQuery보다 나은 점은 무엇입니까? (0) | 2020.05.26 |
---|---|
Spring MVC : GET @RequestParam과 같은 복잡한 객체 (0) | 2020.05.26 |
경고 : 보호되지 않은 개인 키 파일! (0) | 2020.05.26 |
명시 적 도메인을 가진 localhost의 쿠키 (0) | 2020.05.26 |
web.config 변환을 사용하여“바꾸기 또는 삽입”을 수행하는 방법이 있습니까? (0) | 2020.05.26 |