How to fix DOMException: "The URI is malformed." in Angular 6 running HTTP?

Solution Update: Destination URL was wrongly constructed, using double colon operator (::) between IP Address and Operator instead of one, which caused the issue.

I have a project running on MEAN Stack. Node Server is live on one computer while Angular App on other. Angular app is using HTTPClient of angular/common/http to send requests to the Node Server. The requests were working perfectly and fetching data until I restructured the app to add some more features. Now, the angular app request does not reach the node server and returns with undefined error status and body. Upon logging the error object, I got this statement:

DOMException: "The URI is malformed."

Requests from PostMan and Browsers invoking same URL are working perfectly fine on the same device running the angular app. It is only the angular app that is now no more able to land its requests on to the sever. I have tried making new angular project, updating/reinstalling packages, but none has worked so far.

The piece of code on client side which had been perfectly working before is:

import { HttpClient,HttpParams } from '@angular/common/http';
getLiveData(){
    return this._httpClient.get(this.getLiveURL).pipe(catchError(this.handleError));
  }

I expect data in response, however angular request just fails to get to the server side.

Upvotes: 2

Views: 8278

Answers (1)

Sanket Vanani
Sanket Vanani

Reputation: 546

Once, I came to the same issue in ReactJS but at that time I got the solution by doing the below changes:

At the time of error I was having URL like: "https://localhost:8000member/getstate"

Here I was missed the /(slash) b/w port number and member.

And I changed it to: "https://localhost:8000/member/getstate" and it was worked too.

I hope it will work for you too.

Upvotes: 5

Related Questions