将curl转换为PowerShell Invoke-WebRequest
发布时间:2020-12-13 16:58:31 所属栏目:Linux 来源:网络整理
导读:我试图转换这两个curl命令.我只是不确定输出详细信息.如果我的cookie需要I2KBRCK = 1.以及如何进行标头转储. %CURL_FOLDER%curl --verbose --insecure --cookie-jar %OUTPUT_FOLDER%cookiejar.txt --cookie I2KBRCK=1 --data user@web.org --data password
我试图转换这两个curl命令.我只是不确定输出详细信息.如果我的cookie需要I2KBRCK = 1.以及如何进行标头转储.
%CURL_FOLDER%curl --verbose --insecure --cookie-jar %OUTPUT_FOLDER%cookiejar.txt --cookie I2KBRCK=1 --data user@web.org --data password=pass --dump-header %OUTPUT_FOLDER%headers_received_1.txt --output %OUTPUT_FOLDER%curl_output_1.html --location https://website.com/action/doLogin > %OUTPUT_FOLDER%curl_verbose_output.txt 2>&1 %CURL_FOLDER%curl --verbose --insecure --cookie %OUTPUT_FOLDER%cookiejar.txt --form file1=@%TSV_UPLOAD_FILE% --form format="XYZ User License Upload" --form email=email.org --dump-header %OUTPUT_FOLDER%headers_received_2.txt --output %OUTPUT_FOLDER%curl_output_2.html https://website.com/something >> %OUTPUT_FOLDER%curl_verbose_output.txt 2>&1 我将curl命令转换为powershell. $outFilePath = 'C:UsersblahDesktopcurl_output_1.html' $outFilePathVerbose = 'C:UsersblahDesktopcurl_verbose_output.txt' $secpasswd = ConvertTo-SecureString "password" -AsPlainText -Force $mycreds = New-Object System.Management.Automation.PSCredential ("user@web.org",$secpasswd) Invoke-WebRequest -Uri "https://website.com/doLogin" -Credential $mycreds -Verbose -SessionVariable myWebSession -Method Post -OutFile $outFilePath Invoke-WebRequest -InFile $someFile -Uri "https://website.com/something" -Credential $mycreds -Verbose -WebSession $myWebSession -Method Post -OutFile $outFilePath 我尝试将第二个curl命令转换为PowerShell另一种方式,并得到404错误而不是500错误… $body = @" format = "XYZUser License Upload" file1 = $FullPathTSVToSend "@ $gist = Invoke-WebRequest -Body $body -Uri "https://website.com/action/directSubscriptionUpload" -Credential $mycreds -Verbose -WebSession $myWebSession -OutFile $outFilePath -Method Post -ContentType "multipart/form-data" 我用powershell编辑了你建议的新代码…… $content = Get-Content $FullPathTSVToSend $body = @{ 'format' = "XYZUser License Upload"; 'file1' = $( $content); 'email' ="user@web.org" } Invoke-WebRequest -Uri "https://website.com/doLogin" -Credential $mycreds -Verbose -SessionVariable myWebSession -Method Post -OutFile $outFilePath Invoke-WebRequest -Body $body -Uri "https://website.com/something" -Credential $mycreds -Verbose -OutFile $outFilePath2 -Method Post -ContentType "multipart/form-data" -WebSession $myWebSession 但是,我仍然收到第二个Invoke-WebRequest的404错误.我想也许我需要从第一个Invoke-WebRequest命令传递一些东西.但myWebSession应该从第一个curl命令获得cookie I2KBRCK = 1. 解决方法
您需要将表单参数放入哈希中,并确保在请求中包含文件的内容,而不是文件名.
尝试: $body = @{ format = "XYZUser License Upload"; file1 = $(gc $FullPathTSVToSend) } Invoke-WebRequest -Body $body -Uri "https://website.com/action/directSubscriptionUpload" -Credential $mycreds -Verbose -WebSession $myWebSession -OutFile $outFilePath -Method Post -ContentType "multipart/form-data" (编辑:李大同) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |
相关内容
- linux – 如何测试新的cron脚本?
- 如何找出连接到Linux机箱的硬盘?
- linux – 在Docker容器中使用bcrypt的ELF头文件或安装问题
- 使用linux命令sed选择多行
- linux initcwnd和initrwnd通过/etc/sysctl.conf
- linux – 第二次从Proc-FS文件读取时使用lseek()是否安全
- linux – 如何创建一个自动从网络加载kickstart的RHEL / Ce
- Linux网络文件共享服务之samba
- active-directory – Linux AD集成,使用Windows Server 201
- Linux / Unix bash基本脚本awk / sed