NativeScript - nativescript-background-http无法正常工作
问题描述:
我正在尝试发布到我用C#从用NativeScript创建的移动应用程序上制作的webapi。我正在使用nativescript-imagepicker
和nativescript-background-http
。 但是error
事件总是发射。NativeScript - nativescript-background-http无法正常工作
这是我的代码: 我的两个进口:
import * as imagepicker from "nativescript-imagepicker";
import * as bghttp from "nativescript-background-http";
我这是怎么了图像的URI:
SelectImage(): void {
let context = imagepicker.create({
mode: "single"
});
context.authorize()
.then(() => { return context.present() })
.then((selection) => {
selection.forEach((selected) => {
this.signupModel.CIPath = selected.fileUri;
})
}).catch((e) => {
console.log(e);
});
}
这就是我如何努力发布数据:
SignUp(): void {
let session = bghttp.session("image-upload");
let request = {
url: "http://localhost:53286/api/Home/Signup",
method: "POST",
headers: {
"Content-Type": "application/octet-stream",
"File-Name": this.signupModel.CIPath
},
description: "{ 'uploading': 'Uploading file...' }"
};
let task: bghttp.Task;
let params = [{
name: "ImageCI", mimeType: "image/jpeg", filename: this.signupModel.CIPath
}, {
name: "Rut", value: this.signupModel.Rut
}, {
name: "Name", value: this.signupModel.Name
}, {
name: "Address", value: this.signupModel.Address
}, {
name: "Commune", value: this.signupModel.Commune
}, {
name: "PhoneNumber", value: this.signupModel.PhoneNumber
}, {
name: "Email", value: this.signupModel.Email
}, {
name: "Password", value: this.signupModel.Password
}];
task = session.multipartUpload(params, request);
task.on("error", (response: any) => {
console.log(JSON.stringify(response));
alert({title: "Sistema 3 Esferas", message:"Error subiendo imagen...", okButtonText: "Cerrar"});
});
task.on("responded", (response: any) => {
console.log(JSON.stringify(response));
});
}
我该做什么错了?提前致谢。 :)
答
感谢尼克,您的评论。
是的,它的工作。 我不得不改变这一行:
url: "http://localhost:53286/api/Home/Signup"
到:
url: "http://10.0.2.2:53286/api/Home/Signup"
这解决了这个问题。 :)
在模拟器上测试?如果是这样,请记住默认配置不能与'localhost'一起使用 - 请参阅此主题以了解详细信息https://*.com/a/39958955/4936697 –
错误响应是什么? –