Got error after call API in ionic3 Http failure response for (unknown url): 0 Unknown Error"?

//This is our code for pass the data in API tell me anyone how to fix this error?
let headers = new Headers({ ‘Content-Type’: ‘application/json’ });
let options = new RequestOptions({ headers: headers });

	//Pass the data into the API and creat the user
	if(url != "" && url != undefined){
		this.http.post(url, object, options).subscribe(data => {
			console.log(data);
		}, error => {
			console.log(error);
		});
	}

Try to console your url var.
is it defined?

url is propery pass in the API sir this is our url="//localhost:8888/api/seller/create"?

are you testing in browser?
localhost will not work in real device
also, try to open the link in browser and check if it is working

Yes i have used a browser not any device?

can you print the console error here

let private_options = { headers: new HttpHeaders({ ‘Content-Type’: ‘application/x-www-form-urlencoded; charset=UTF-8’ }) };

this.http.post(App.apis.registeruser,data,private_options)
.retry(3)
.subscribe(res => {
resolve(res);
}, (err) => {
console.log(err);
});

use this one…

1 Like

sir why pass 3 in the retry(3)?

its up to you…
if api fails then it will call for 3 times as i know…
just get some little bit knowledge about promises…

1 Like

Sir have add “proxies”: [
{
“path”: “/api”,
“proxyUrl”: “http://cors.api.com/api
}
]
in our ionic.config.json file but i got another error here
Argument of type ‘{ headers: Headers; }’ is not assignable to parameter of type ‘RequestOptionsArgs’.

pls show me your entire page code with import

did you fix it? Having same issue

some one can say me how can fix that??
i am trying connect to mulesoft endpoint but give that error

I’m have the same error on Ionic 4.0.0-BETA2 for Edge Browser

I’m try to put this on ionic.config.json but didn’t solve my problem.

The problem is with the HTTP request. When I try to do a GET request I received an console error. See the details:

My .ts code

this.http
      .get<any[]>(this.url) //the return is an array
      .pipe(map(data => data[0]))
      .subscribe(
        value => {
          console.log(value); //this line is not called
        }
      )

Edge Console ERROR on start of the application:

[object Object]: {error: Object, headers: Object, message: "Http failure response for (unknown url): 0 Unknown Error", name: "HttpErrorResponse", ok: false...}

error: Object

headers: Object
message: "Http failure response for (unknown url): 0 Unknown Error"
name: "HttpErrorResponse"
ok: false
status: 0
statusText: "Unknown Error"
url: null

__proto__: Object

But the URL is right because the project ran withou errors on Chrome and Firefox.

Hi, any fix yet? I’m having this problem now

1 Like

Did you find any solutions ?

@amitgsk: sir i fixed it actually its a backend issue not at the front end issue.actually at backend side ‘Access-origin’ is not added at backend so discuss with backend developer and set access origin at backend.

Thank you for replying I have solved this issue using this post Ionic3 + HTTP call + Android 9.0.4
I do have CORS handled in back end because am myself also developing the back end with the help of Web Api 2 if you have any thing more suggestion please let me know.