【发布时间】:2017-05-03 23:13:15
【问题描述】:
我正在尝试使用FileTransfer method 将文件从PhoneGap 上传到服务器。我需要为此上传启用 HTTP 基本身份验证。
以下是相关代码:
var options = new FileUploadOptions({
fileKey: "file",
params: {
id: my_id,
headers: { 'Authorization': _make_authstr() }
}
});
var ft = new FileTransfer();
ft.upload(image, 'http://locahost:8000/api/upload', success, error, options);
Looking over the PhoneGap source code 似乎我可以通过在“params”列表中包含“headers”来指定授权标头,就像我在上面所做的那样:
JSONObject headers = params.getJSONObject("headers");
for (Iterator iter = headers.keys(); iter.hasNext();)
{
String headerKey = iter.next().toString();
conn.setRequestProperty(headerKey, headers.getString(headerKey));
}
但是,这似乎并没有真正添加标题。
那么:有没有办法使用 PhoneGap 的 FileTransfer 对 iPhone 和 Android 进行 HTTP 基本身份验证?
【问题讨论】:
-
对于任何想知道的人,上面列出的这种方法对我有用。只需要添加这个:
params.headers = {Authorization: 'Basic ' + creds}; options.params = params; -
headers 需要去 options.headers 没有添加到 options.params.____