我试图从特定文件夹中获取文件,使用curl加载它们并将结果输入变量:
Dim strURL
Dim HTTP
Dim dataFile
Dim dataRequest
Dim objStream
strURL = "http://localhost/uploadfile.php?parameter1=mytest1¶meter2=hello¶meter3=thankyou"
Set HTTP = CreateObject("Microsoft.XMLHTTP")
Set objStream = CreateObject("ADODB.Stream")
objStream.Type = 2
objStream.Open
objStream.LoadFromFile "c:\1234.txt"
dataFile = objStream.ReadText
dataRequest = "filechoice=" & dataFile
HTTP.open "POST", strURL, False
HTTP.setRequestHeader "Content-Type", "application/x-www-form-urlencoded"
HTTP.setRequestHeader "Content-Length", Len(dataRequest)
WScript.Echo "Now uploading file"
HTTP.send dataRequest
WScript.Echo HTTP.responseText
Set HTTP = Nothing
运行此脚本的结果是
#!/bin/bash
shopt -s nullglob
FILES=*
for f in $FILES
do
core=$f
#echo "curl -H \"Content-Type: application/json\" --data-binary @$f http://v-cdh-master:8983/solr/$core/update/json?commit=true"
result=$(curl -H "Content-Type: application/json" -s --data-binary @$f http://v-cdh-master:8983/solr/$core/update/json?commit=true)
done
如果我从echo字符串中删除评论,我可以看到像这样的有效网址
curl: no URL specified!
curl: try 'curl --help' or 'curl --manual' for more information
当我将其复制/粘贴到终端时,哪种方法很完美。
我的错误在哪里?
答案 0 :(得分:2)
URL中的?
导致整个参数被视为glob,它与文件不匹配。由于您启用了nullglob
选项,因此该字词会从对curl
的调用中删除。引用参数,就像使用echo
命令一样,将通过阻止路径名生成来解决问题。
result=$(curl -H "Content-Type: application/json" -s --data-binary @"$f" "http://v-cdh-master:8983/solr/$core/update/json?commit=true")