ajax - API 通过 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"
解决方案
推荐阅读
- apache-kafka - 为了支持 18 台 kafka 机器,我们需要多少个 zookeper 服务器
- python-3.x - 有循环中断列表框?
- angular - 概括休息服务调用并将服务器响应映射到我的对象
- python - 在 Ansbile Vault 中存储密码并使用 API 从 Python 脚本中检索该密钥
- iis - 在 ASP.NET 中使用 QUERY_STRING 重写特定条件的 URL
- r - 在文本文件中的特定行之间粘贴文本?(右)
- r - 在 R 中重新组织数据框
- java - 如何在 JAVA 中将字符串变量转换回字节 []
- jquery - Ajax 发布到 Laravel API 访问错误
- python - 将元组转换为机器学习研究中特征的字符串