程序问答   发布时间:2022-06-02  发布网站:大佬教程  code.js-code.com
大佬教程收集整理的这篇文章主要介绍了格式化 curl 命令大佬教程大佬觉得挺不错的,现在分享给大家,也给大家做个参考。

如何解决格式化 curl 命令?

开发过程中遇到格式化 curl 命令的问题如何解决?下面主要结合日常开发的经验,给出你关于格式化 curl 命令的解决方法建议,希望对你解决格式化 curl 命令有所启发或帮助;

在 windows Git Bash 中,此 curl 命令有效:

<com.Google.androID.material.textfIEld.TexTinputLayout
        androID:layout_wIDth="match_parent"
        androID:layout_height="wrap_content"
        style="@style/Widget.MaterialComponents.TexTinputLayout.outlinedBox"
        androID:hint="Username"
        androID:textcolorHint="@color/black"
        app:Boxstrokecolor="@color/black"
        app:BoxstrokeWIDthFocused="2dp"
        app:enDiconTint="@color/black"
        app:hintTextcolor="@color/black"
        app:enDiconMode="clear_text"
        app:startIconTint="@color/black"
        androID:ID="@+ID/signup_username_editText"
        >

        <com.Google.androID.material.textfIEld.TexTinputEditText
           
            androID:layout_wIDth="match_parent"
            androID:layout_height="match_parent"
            androID:inputType="text"
            androID:textcolor="@color/black"
            androID:textcursorDrawable="@null" />
    </com.Google.androID.material.textfIEld.TexTinputLayout>

但是当我尝试在 -d 中格式化内容时,它不起作用:

curl -v 'https://developer.API.autodesk.com/authentication/v1/authenticate' \
  -X 'POST' \
  -H 'Content-Type: application/x-www-form-urlencoded' \
  -d 'clIEnt_ID=6BfkncD9ypgmiHkjrfka5ydqrG4GLx1z&clIEnt_secret=EC5i7QG61Qg8jDmZ&grant_type=clIEnt_credentials&scope=data:read'

无论如何我可以格式化它并且它可以工作吗?

解决方法

curl 的 -d/--data/--data-ascii 选项发送一个数据,在 URL paraleters 的情况下,该数据预计在一行中(与 JSON 相反,如 seen for instance here,其中数据可以在多行上) .

这意味着您需要先在变量中构建字符串,然后在 curl 中使用该变量。

vonc@vclp MINGW64 /c/test
$ data=$(printf '%s' '
    client_id=6BfkncD9ypGMiHkjrfka5ydqrG4GLx1z&
    client_secret=EC5i7QG61Qg8jDmZ&
    grant_type=client_credentials&
    scope=data:read
' | sed ':a; N; $!ba; s/\n\s*//g')

curl -v 'https://developer.api.autodesk.com/authentication/v1/authenticate' \
  -X 'POST' \
  -H 'Content-Type: application/x-www-form-urlencoded' \
  -d "${data}"

在这种情况下有两个步骤。

大佬总结

以上是大佬教程为你收集整理的格式化 curl 命令全部内容,希望文章能够帮你解决格式化 curl 命令所遇到的程序开发问题。

如果觉得大佬教程网站内容还不错,欢迎将大佬教程推荐给程序员好友。

本图文内容来源于网友网络收集整理提供,作为学习参考使用,版权属于原作者。
如您有任何意见或建议可联系处理。小编QQ:384754419,请注明来意。