Curl

這個 curl 命令有什麼作用?

  • March 9, 2019

我對 Unix 真的很陌生,我不知道這個命令是做什麼的。據我了解,它向網站發送 HTTP POST 請求。我不知道每一行應該做什麼。每條線的作用是什麼?

這是命令:

curl http://www.example.com/xmlrpc.php -d 
   '
   pingback.ping
   http://destination.site.com/

   http://www.example.com/
   '

這很可能是一個 Wordpress 網站。該xmlrpc.php腳本是一個 PHP 腳本,它提供遠端過程呼叫(因此名稱中包含 rpc),它允許您在伺服器上執行東西。這些就像類中的方法。

例子

<?xml version="1.0"?>
<methodCall>
  <methodName>pingback.ping</methodName>
  <params>
     <param>
       <value><string>http://.source./</string></value>
     </param>
     <param>
       <value><string>http://.target./</string></value>
     </param>
  </params>
</methodCall>

當您在範例中呼叫 URL 時,您正在呼叫該pingback.ping方法並在呼叫後提供 URL 作為該方法的參數。第一個 URL 是 pingback 的源 URL,而第二個是目標 URL。

curl 的 -d 開關

curl的手冊頁:

-d/--data <data>
     (HTTP) Sends the specified data in a POST request to the HTTP server, 
     in a way that can emulate as if a user has filled in a HTML form and 
     pressed the submit  button.  Note  that  the  data  is  sent exactly 
     as specified with no extra processing (with all newlines cut off).  
     The data is expected to be "url-encoded". This will cause curl to pass 
     the data to the server using the content-type 
     application/x-www-form-urlencoded. Compare to -F/--form. If this 
     option is used more than once on the same command line, the data 
     pieces specified will be merged together with a separating &-letter. 
     Thus, using ’-d name=daniel -d skill=lousy’ would generate a post 
     chunk that looks like ’name=daniel&skill=lousy’.

     If  you  start  the  data  with  the  letter @, the rest should be a 
     file name to read the data from, or - if you want curl to read the 
     data from stdin.  The contents of the file must already be 
     url-encoded. Multiple files can also be specified. Posting data from a 
     file named ’foobar’ would thus be done with --data @foobar".

     To post data purely binary, you should instead use the --data-binary 
     option.

     -d/--data is the same as --data-ascii.

     If this option is used several times, the ones following the first 
     will append data.

引用自:https://unix.stackexchange.com/questions/111076