Movatterモバイル変換


[0]ホーム

URL:


everything curl

    -d vs -F

    Previous chapters talked aboutregular POST andmultipart formpost, and in your typical command lines you dothem with-d or-F.

    When do you use which of them?

    As described in the chapters mentioned above, both these options send thespecified data to the server. The difference is in how the data isformatted over the wire. Most of the time, the receiving end is written toexpect a specific format and it expects that the sender formats and sends thedata correctly. A client cannot just pick a format of its own choice.

    HTML web forms

    When we are talking browsers and HTML, the standard way is to offer a form tothe user that sends off data when the form has been filled in. The<form>tag is what makes one of those appear on the webpage. The tag instructs thebrowser how to format its POST. If the form tag includesenctype=multipart/form-data, it tells the browser to send the data as amultipart formpost which you make with curl's-Foption. This method is typically used when the form includes a<input type=file> tag, for file uploads.

    The defaultenctype used by forms, which is rarely spelled out in HTML sinceit is default, isapplication/x-www-form-urlencoded. It makes the browserURL encode the input as name=value pairs with the data encoded to avoid unsafecharacters. We often refer to that as aregular POST, and youperform one with curl's-d and friends.

    POST outside of HTML

    POST is a regular HTTP method and there is no requirement that it be triggeredby HTML or involve a browser. Lots of services, APIs and other systems allowyou to pass in data these days in order to get things done.

    If these services expect plain raw data or perhaps data formatted as JSON orsimilar, you want theregular POST approach. curl's-d optiondoes not alter or encode the data at all but just sends exactly what you tellit to. Just pay attention that-d sets a defaultContent-Type: that mightnot be what you want.


    [8]ページ先頭

    ©2009-2025 Movatter.jp