通过PowerShell使用上传文件的API

时间:2018-07-22 17:26:56

标签: ajax powershell

我正在尝试通过API将apk文件上传到我们的云中。

在POSTMAN上进行测试时,一切正常 但是当我尝试将其转换为PowerShell时,它根本无法工作。

以下是AJAX上的相关参数:

var form = new FormData();
form.append("app-data", "Netflix_v6.7.1_build_28752_apkpure.com.apk");
form.append("newVersion", "true");
form.append("Partver", "22222");
form.append("platformType", "ANDROID");

var settings = {
  "async": true,
  "crossDomain": true,
  "url": "https://URL",
  "method": "POST",
  "headers": {
    "authorization": "Basic CodeHere",
    "cache-control": "no-cache",
    "postman-token": "b581369a-98sas-a49d-231e-sddsadsadsaf2"
  },
  "processData": false,
  "contentType": false,
  "mimeType": "multipart/form-data",
  "data": form
}

$.ajax(settings).done(function (response) {
  console.log(response);
});

我的代码:

[Net.ServicePointManager]::SecurityProtocol = [Net.SecurityProtocolType]::Tls12
$headers = New-Object "System.Collections.Generic.Dictionary[[String],[String]]"
$headers.Add("authorization", "Basic CodeHere")
$headers.Add("cache-control", "no-cache")
$headers.Add("postman-token", "b581369a-98sas-a49d-231e-sddsadsadsaf2")

$ori = "app-data"
$url = "https://URL"
$person = @{
    "app-data"    = "\\server\Netflix_v6.7.1_build_28752_apkpure.com.apk"
    newVersion    = 'true'
    cmPartitionId = '22222'
    platformType  = 'ANDROID'
}
$body = (ConvertTo-Json $person)

Invoke-RestMethod -Uri $url -Headers $headers -Body $body -Method Post -ContentType "multipart/form-data"

0 个答案:

没有答案