如何解决cURL-带有文件路径位置的文件上传不适用于Windows命令提示符
我正在尝试使用Windows命令提示符下的cURL命令将文件发送到服务器。但是得到的错误消息为“ {” detail“:” JSON解析错误-无法解码JSON对象“}” 。但是使用邮递员,我可以将文件发送到服务器。下面提供了详细信息。
以下是我尝试通过仅发送文件位置来发送/上传文件的两个cURL命令:
curl --insecure -F user_file=@"C:/Users/402096/Desktop/dau_settings-123.conf" -H "Content-Type: application/json" -H "Authorization: Token 3f98d0a178ddd176faea94e6d629621920d203b2624550e68a" -X POST https://10.107.12.123/import_config
curl --insecure -F "user_file=@C:/Users/402096/Desktop/dau_settings-123.conf" -H "Content-Type: application/json" -H "Authorization: Token 3f98d0a178ddd176faea94e6d629621920d203b2624550e68a" -X POST https://10.107.12.123/import_config
@api_view(["POST","GET"])
@permission_classes((IsAuthenticated,))
@permission_required('dau_gui_app.execute_import_config')
def import_config_view(request):
if request.method == 'POST' and request.FILES['user_file']:
user_file = request.FILES['user_file']
fs = FileSystemStorage()
filename = fs.save( user_file.name,user_file)
filePath = fs.location + "/" + filename
print filePath
message ="{\
\"command\":\"execute\",\
\"subcommand\":\"import_config\",\
\"args\": [{\"file_path\":\"" + filePath + "\"}]}"
message.replace(" ","")
try:
response = send_cmd(message)
except:
print("An exception occurred sending the message:")
print(message)
#end try
fs.delete(filename)
return HttpResponse(response,content_type='application/json')
return render(request,'dau_gui_app/import_config.html',{'title':"Import Configuration" })
注意: 我可以使用邮递员成功上传文件。当我查看邮递员用来上传/发送文件的cURL代码时,我在邮递员中看到了下面的cURL。但是,当我在Windows命令提示符下键入相同的命令时,却出现了与语法和格式有关的错误。
curl -X POST 'https://10.107.12.123/import_config' -H 'Content-Type: application/json' -H 'Authorization: Token 3f98d0a178ddd176faea94e6d629621920d203b2624550e68a' -H 'Cookie: csrftoken=wC4LbjwDsh5BkRPi7TgwZN2FbQLMmpuz; sessionid=7xq7jv95j50k6lkojbrkp2ndgfczfe9v' -F 'user_file=@/C:/Users/402096/Desktop/dau_settings-123.conf'
请帮助我如何使用Windows命令提示符下的cURL将文件发送/上传到django服务器。不知道我在这里错过了什么
解决方法
您需要安装curl并在环境变量中设置路径。 从此处签出安装步骤: https://develop.zendesk.com/hc/en-us/articles/360001068567-Installing-and-using-cURL#install
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。