Problem: http.post()
returns
Error: java.net.MalformedURLException: Protocol not found: 192.168.1.14:8080/newuser at ZoneAwareError
Code (user.service.ts):
import { Injectable } from "@angular/core";
import { Http, Headers, Response } from "@angular/http";
import { Observable } from "rxjs/Rx";
import "rxjs/add/operator/do";
import "rxjs/add/operator/map";
import { User } from "./user";
import { Config } from "../config";
@Injectable()
export class UserService {
constructor(private http: Http) {}
register(user: User) {
let headers = new Headers();
headers.append("Content-Type", "application/json");
return this.http.post(
"192.168.1.14:8080/newuser",
JSON.stringify({
username: user.email,
password: user.password
}),
{ headers: headers }
)
.catch(this.handleErrors);
}
handleErrors(error: Response) {
console.log(JSON.stringify(error.json()));
return Observable.throw(error);
}
}
Following through the groceries tutorial (Chapter 3: Services), I couldn't access the backend api for the users so I wrote my own using NodeJS
(hosting on an OPi on my network). I can post using my dev comp, and I can access a GET
request from the browser of the emulator, but when I try to post the IP:port I get a MalformedURLException
.
How can I post to this URL? All of the Nativescript http.post()
examples I could find use DNS-based URLs; is it even possible to do IP-based requests?