Kaip siųsti antraštę, naudojant HTTP užklausą per garbaną?

Noriu siųsti antraštę į „Apache“ serverį „Linux“ dėžutėje. Kaip tai pasiekti su garbanotais skambučiais?

895
10 дек. set gagneet 10 dec. 2008-12-10 19:38 '08, 07:38 pm 2008-12-10 19:38
@ 7 atsakymai

man curl :

  -H/--header <header> (HTTP) Extra header to use when getting a web page. You may specify any number of extra headers. Note that if you should add a custom header that has the same name as one of the internal ones curl would use, your externally set header will be used instead of the internal one. This allows you to make even trickier stuff than curl would normally do. You should not replace internally set headers without knowing perfectly well what you're doing. Remove an internal header by giving a replacement without content on the right side of the colon, as in: -H "Host:". curl will make sure that each header you add/replace get sent with the proper end of line marker, you should thus not add that as a part of the header content: do not add newlines or carriage returns they will only mess things up for you. See also the -A/--user-agent and -e/--referer options. This option can be used multiple times to add/replace/remove multi- ple headers. 

Pavyzdys:

 curl --header "X-MyHeader: 123" www.google.com 

Galite matyti užklausą, kuri yra sumažinta pridedant -v .

1362
10 дек. Atsakymas duotas Taderiui gruodžio 10 d. 2008-12-10 19:41 '08 at 7:41 pm 2008-12-10 19:41

Gaukite

su JSON:

 curl -i -H "Accept: application/json" -H "Content-Type: application/json" http://hostname/resource 

su XML:

 curl -H "Accept: application/xml" -H "Content-Type: application/xml" -X GET http://hostname/resource 

POST

Jei norite skelbti duomenis:

border=0
 curl --data "param1=value1 http://hostname/resource 

Jei norite atsisiųsti failą:

 curl --form "fileupload=@filename.txt" http://hostname/resource 

Atnaujinamas HTTP pranešimas:

 curl -X POST -d @filename http://hostname/resource 

Jei norite įvesti svetainę (auth):

 curl -d "username=admin --dump-header headers http://localhost/Login curl -L -b headers http://localhost/ 
258
07 окт. Atsakymas pateikiamas R aikštėje spalis 07. 2013-10-07 08:15 '13, 08:15 am 2013-10-07 08:15

Į php

 curl_setopt($ch,CURLOPT_HTTPHEADER,array('HeaderName: HeaderValue')); 

arba galite įdiegti kelis

 curl_setopt($ch,CURLOPT_HTTPHEADER,array('HeaderName: HeaderValue','HeaderName2: HeaderValue2')); 
247
03 апр. Atsakymą pateikė Jamesas balandžio 3 d. 2010-04-03 12:49 '10, 12:49, 2010-04-03 12:49

Naudokite -H or --header .

41
10 дек. atsakymas, kurį pateikė Greg 10 Dec. 2008-12-10 19:41 '08 at 7:41 pm 2008-12-10 19:41

GET (keli parametrai):

 curl -X GET "http://localhost:3000/action?result1=gh> 

arba

 curl --request GET "http://localhost:3000/action?result1=gh> 

arba

 curl "http://localhost:3000/action?result1=gh> 

arba

 curl -i -H "Application/json" -H "Content-type: application/json" "http://localhost:3000/action?result1=gh> 
34
14 окт. Atsakymą pateikė Vietnhi Phuvan spalio 14 d. 2015-10-14 12:44 '15, 12:44 2015-10-14 12:44

Persijungiau nuo garbanos prie Httpie ; Sintaksė yra:

 http http://myurl HeaderName:value 
5
02 сент. Atsakymą pateikė Graham Perks 02 Sep. 2015-09-02 23:39 '15 at 11:39 2015-09-02 23:39

Jei norite siųsti savo pasirinktines antraštes , galite tai padaryti.

 curl -v -H @{'custom_header'='custom_header_value'} http://localhost:3000/action?result1=gh> 
0
09 авг. atsakymas duotas Palsri 09 rug . 2017-08-09 13:27 '17, 13:27 pm 2017-08-09 13:27

Kiti klausimai apie „ arba „ Užduoti klausimą“