Como faço para enviar solicitações GET e POST usando o Curl?

1

Como faço para enviar solicitações GET e POST com o parâmetro gimmeflag e o valor please para a URL http://103.200.7.150:7777/ usando curl na linha de comando?

    
por raka widiana 24.10.2017 / 18:14

2 respostas

5

Parece que você está seguindo um tutorial ou um livro, e essa é uma maneira insolente de testar se você aprendeu o básico.

Calling http://103.200.7.150:7777/ via curl or browser yields the following output:

Please send me request method GET and POST with params "gimmeflag" and value "please"

Vamos dividi-lo em duas partes, já que você quer saber como é feito com curl (veja man 1 curl ou o manual de curvas ).

Usando GET para enviar sua solicitação:

Este é muito fácil se você souber como se parece um query-string .

On the World Wide Web, a query string is the part of a uniform resource locator (URL) containing data that does not fit conveniently into a hierarchical path structure. The query string commonly includes fields added to a base URL by a Web browser or other client application, for example as part of an HTML form.

A web server can handle a Hypertext Transfer Protocol request either by reading a file from its file system based on the URL path or by handling the request using logic that is specific to the type of resource. In cases where special logic is invoked, the query string will be available to that logic for use in its processing, along with the path component of the URL.(source)

Você deseja enviar um parâmetro gimmeflag e um valor please . Portanto, a linha que você deseja solicitar com curl é:

curl -X GET http://103.200.7.150:7777/?gimmeflag=please

The result you get back from the server:

KSL{n0w_y0u_Know_How_To

Usando o POST para enviar sua solicitação:

Dada a linha GET, o POST é muito fácil, apenas substitua o GET pelo POST:

curl -X POST http://103.200.7.150:7777/?gimmeflag=please

The result you get back from the server:

_S3nD_r3quesT_Meth0d_GET_AND_POST}

Para concluir isto:

# Thanks to @pa4080 for this line
printf '%s%s\n' \
"$(curl -X GET http://103.200.7.150:7777/?gimmeflag=please 2>/dev/null)" \
"$(curl -X POST http://103.200.7.150:7777/?gimmeflag=please 2>/dev/null)"

KSL{n0w_y0u_Know_How_To_S3nD_r3quesT_Meth0d_GET_AND_POST}

    
por Videonauth 24.11.2017 / 20:06
2

Esta resposta mostra como os resultados da resposta @ Videonauth , mas com% co_de, podem ser alcançados % :

$ wget -qO- http://103.200.7.150:7777/ 
Please send me request method GET and POST with params "gimmeflag" and value "please"
$ wget -qO- http://103.200.7.150:7777/?gimmeflag=please # GET is the default request
KSL{n0w_y0u_Know_How_To
$ wget -qO- --post-data '' http://103.200.7.150:7777/?gimmeflag=please # Simple POST req.
_S3nD_r3quesT_Meth0d_GET_AND_POST}
$ printf '\n%s%s\n' \
"$(wget -qO- http://103.200.7.150:7777/?gimmeflag=please 2>/dev/null)" \
"$(wget -qO- --post-data '' http://103.200.7.150:7777/?gimmeflag=please 2>/dev/null)"

KSL{n0w_y0u_Know_How_To_S3nD_r3quesT_Meth0d_GET_AND_POST}

Em wget :

-O file; --output-document=file - The documents will not be written to the appropriate 
     files, but all will be concatenated together and written to file. If '-' is used 
     as file, documents will be printed to standard output, disabling link conversion...

-q; --quiet - Turn off Wget's output.

--post-data=string; --post-file=file - Use POST as the method for all HTTP requests 
     and send the specified data in the request body. --post-data sends string as data, 
     whereas --post-file sends the contents of file. Other than that, they work in 
     exactly the same way. In particular, they both expect content of the form 
     "key1=value1&key2=value2", with percent-encoding for special characters... 
     Only one of --post-data and --post-file should be specified... This example shows 
     how to log in to a server using POST and then proceed to download the desired pages, 
     presumably only accessible to authorized users:

         # Log in to the server.  This can be done only once.
         wget --save-cookies cookies.txt --post-data 'user=foo&password=bar' \
         http://example.com/auth.php
    
por pa4080 24.11.2017 / 21:39