http POST invoke-WebRequest参数添加文本

时间:2017-05-31 15:10:13

标签: powershell http batch-file httpwebrequest invoke-command

我可以显示纯文本,我可以先获取变量,然后显示文本 - 但是,我试图获取一个标签,然后是变量:

powershell -Command "& {Invoke-WebRequest -Uri https://script.google.com/macros/s//exec -Method POST -Body text="$env:computername, $env:os, $env:username, $env:thisip"}"

返回错误。

我使用的批处理命令是:

powershell -Command "& {Invoke-WebRequest -Uri https://script.google.com/macros/s//exec -Method POST -Body text="ComputerName: $env:computername, OS: $env:os, UserName: $env:username, IP: $env:thisip"}"

我想简单地在Command中标记每个变量,例如:

class Target(models.Model):
    name = models.TextField()

class Task(models.Model):
    targets = models.ManyToManyField(Target)
    section = models.ForeigKey(Section)

class Section(models.Model):
     name = models.TextField()

然而,我继续得到关于位置参数的错误。

感谢任何帮助!

1 个答案:

答案 0 :(得分:0)

@ thepip3r正确指出:

  

看起来您的问题与单个内容中的单引号有关   引号。您需要双引号内部单引号或字符串   被解释为在字符串中间被终止。

我改为以下并且有效:

powershell -Command "& {Invoke-WebRequest -Uri https://script.google.com/macros/s//exec -Method POST -Body text='ComputerName: $env:computername, OS: $env:os, UserName: $env:username, IP: $env:thisip'}"

相关问题