发送带有发布httpClient ionic的数组字符串

时间:2019-03-04 19:02:16

标签: web-services ionic-framework http-post httpclient arrayobject

我想发送参数并获取其他参数,但是我使用ionic的HttpClient的post方法发送这些参数(字符串和字符串数组)的方法遇到问题。

错误(不是CORS安全性,因为我也使用设备运行并且遇到相同的问题):

Failed to load resource: the server responded with a status of 404 (Not Found).

Access to XMLHttpRequest at 'http://localhost:64411/getLabels' from origin 'http://localhost:8100' has been blocked by CORS policy: Response to preflight request doesn't pass access control check: It does not have HTTP ok status.

我的离子代码:

var apiURL = 'http://localhost:64411/';
pathGetLabels: string = apiURL + 'getLabels';

constructor(public http: HttpClient, public material: MaterialProvider, public hp : Http) {
     }
loadLabels(lbls: any){
        return this.http.post(this.pathGetLabels, lbls ,Language);}

该数组没有问题,这是:

Array(6)
0: "USER"
1: "Password"
2: "SaveAccount"
3: "lbl_login"
4: "ForgetPass"
5: "Register"
length: 6

以及Web Service Api Rest的代码:

[Route("getLabels/{paramOne}/{paramTwo}")]
        public HttpResponseMessage getLabels([FromBody]string[] paramOne, string idL)
        {
            var labels = LanguagesRepository.GetLabels(paramOne, idL);
            HttpResponseMessage response = Request.CreateResponse(HttpStatusCode.OK, labels);

            return response;
        }

我试图做这些事情,但遇到了同样的问题:

return this.http.get(this.pathGetLabels+ JSON.stringify(lbls) +"/"+Language);
return this.http.get(this.pathGetLabels+ JSON.stringify(lbls), Language);

0 个答案:

没有答案