执行使用curl多个请求,使用不同的选项 [英] Performing multiple requests using curl, with different options

查看:200
本文介绍了执行使用curl多个请求,使用不同的选项的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图用卷曲将文件上载到SharePoint。 (即3个独立的卷曲调用,检查出该文件,上传,并检查回),我可以分三个步骤成功地做到这一点,使用中的建议以下职位:

I'm trying to use curl to upload a file to sharepoint. I can do this successfully in three steps (ie. 3 separate invocations of curl to check the file out, upload it, and check it back in), using the suggestions in the following post:

<一个href=\"http://stackoverflow.com/questions/17772564/how-to-check-out-a-file-from-sharepoint-document-library-using-curl\">How使用curl检查出从SharePoint文档库中的文件?

我个人的要求如下:

# Checkout the index.html file
curl --ntlm --user ${USER} \
    --data @- \
    -H "SOAPAction: http://schemas.microsoft.com/sharepoint/soap/CheckOutFile" \
    -H "Content-Type: text/xml; charset=utf-8" \
    ${SHAREPOINT}/_vti_bin/Lists.asmx << EOF
<?xml version="1.0" encoding="utf-8"?>
<soap:Envelope xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema">
  <soap:Body>
    <CheckOutFile xmlns="http://schemas.microsoft.com/sharepoint/soap/">
      <pageUrl>${FILE}</pageUrl>
      <checkoutToLocal>false</checkoutToLocal>
      <lastmodified/>
    </CheckOutFile>
  </soap:Body>
</soap:Envelope>
EOF

# upload the file
curl --ntlm -u ${USER} \
    -T HTML/2015/index.html \
    ${FOLDER}

curl --ntlm --user ${USER} \
    --data @- \
    -H "SOAPAction: http://schemas.microsoft.com/sharepoint/soap/CheckInFile" \
    -H "Content-Type: text/xml; charset=utf-8" \
    ${SHAREPOINT}/_vti_bin/Lists.asmx << EOF
<?xml version="1.0" encoding="utf-8"?>
<soap:Envelope xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/">
  <soap:Body>
    <CheckInFile xmlns="http://schemas.microsoft.com/sharepoint/soap/">
      <pageUrl>${FILE}</pageUrl>
      <comment>Automagic update</comment>
      <checkinType>0</checkinType>
    </CheckInFile>
  </soap:Body>
</soap:Envelope>
EOF

不幸的是,这将导致cUrl作者问我要我的密码3次(这是一个长的密码!:-))。我也不喜欢.netrc文件的主意,因为密码写入到磁盘是不是一个好主意。

Unfortunately, this results in cUrl asking me for my password 3 times (and it's a long password! :-) ). I also don't like the idea of a .netrc file, since writing passwords to disk is not a great idea.

所以,我想我也许可以做的是所有的请求组合成一个命令行设置和删除必要的报头,并酌情提供请求机构使用bash进程替换等。

So, what I thought I might be able to do is combine all of the requests into a single command line, setting and deleting headers as necessary, supplying the request bodies as appropriate using bash process substitution, etc.

curl --ntlm --user ${USER} \
    --trace-ascii publish.log \
    --data @<(echo "$CHECKOUT") \
    -H "SOAPAction: http://schemas.microsoft.com/sharepoint/soap/CheckOutFile" \
    -H "Content-Type: text/xml; charset=utf-8" \
    ${SHAREPOINT}/_vti_bin/Lists.asmx \
    -H "SOAPAction:" \
    -H "Content-Type:" \
    -T HTML/2015/index.html \
    ${FOLDER} \
    --data @<(echo "$CHECKIN") \
    -H "SOAPAction: http://schemas.microsoft.com/sharepoint/soap/CheckInFile" \
    -H "Content-Type: text/xml; charset=utf-8" \
    ${SHAREPOINT}/_vti_bin/Lists.asmx

不幸的是,什么情况是,似乎cUrl作者来处理所有的选项一次,然后才尝试将请求的URL,致使选项为另一个URL,最终没有工作一个网址,覆盖选项。从日志文件的片段:

Unfortunately, what happens is that cUrl seems to process all of the options at once, and only then attempt to request the URL's, resulting in options for one URL overwriting options for another URL, and ultimately nothing working. A snippet from the log file:

> 0000: PUT /xxx/xxx/_vti_bin/Lists.asmx HTTP/1.1
> 0033: Authorization: NTLM AAAAAAAAAAA=
> 0075: User-Agent: curl/7.30.0
> 008e: Host: example.com
> 00a8: Accept: */*
> 00b5: SOAPAction: http://schemas.microsoft.com/sharepoint/soap/CheckOu
> 00f5: tFile
> 00fc: Content-Type: text/xml; charset=utf-8
> 0123: SOAPAction: http://schemas.microsoft.com/sharepoint/soap/CheckIn
> 0163: File
> 0169: Content-Type: text/xml; charset=utf-8
> 0190: Content-Length: 0
> 01a3: Expect: 100-continue

注意重复的SOAPAction头,而我希望只有应用的第一个选项。

Notice the duplicated SOAPAction header, while I was hoping to only have the first options applied.

有什么办法说停止处理选项现在,做这个URL,然后再进行?

Is there any way to say "stop processing options now, do this URL, then carry on"?

推荐答案

如果输入三次密码是你唯一的关注,你可以提示用户输入密码,并在一个变量读它,并用它在curl命令像下面。

If typing password three times is your only concern, you can prompt for the password and read it in a variable and use it in curl command as like below.

echo "Password: "
read -s PASSWORD
# Checkout the index.html file
curl --ntlm --user ${USER}:${PASSWORD} \
    --data @- \
    -H "SOAPAction: http://schemas.microsoft.com/sharepoint/soap/CheckOutFile" \
    -H "Content-Type: text/xml; charset=utf-8" \
    ${SHAREPOINT}/_vti_bin/Lists.asmx << EOF
<?xml version="1.0" encoding="utf-8"?>
<soap:Envelope xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/">
  <soap:Body>
    <CheckOutFile xmlns="http://schemas.microsoft.com/sharepoint/soap/">
      <pageUrl>${FILE}</pageUrl>
      <checkoutToLocal>false</checkoutToLocal>
      <lastmodified/>
    </CheckOutFile>
  </soap:Body>
</soap:Envelope>
EOF

# upload the file
curl --ntlm -u ${USER}:${PASSWORD} \
    -T HTML/2015/index.html \
    ${FOLDER}

curl --ntlm --user ${USER}:${PASSWORD} \
    --data @- \
    -H "SOAPAction: http://schemas.microsoft.com/sharepoint/soap/CheckInFile" \
    -H "Content-Type: text/xml; charset=utf-8" \
    ${SHAREPOINT}/_vti_bin/Lists.asmx << EOF
<?xml version="1.0" encoding="utf-8"?>
<soap:Envelope xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/">
  <soap:Body>
    <CheckInFile xmlns="http://schemas.microsoft.com/sharepoint/soap/">
      <pageUrl>${FILE}</pageUrl>
      <comment>Automagic update</comment>
      <checkinType>2</checkinType>
    </CheckInFile>
  </soap:Body>
</soap:Envelope>
EOF

这篇关于执行使用curl多个请求,使用不同的选项的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆