問題:http.post()
戻りNativescript http.post()でMalformedURLException
Error: java.net.MalformedURLException: Protocol not found: 192.168.1.14:8080/newuser at ZoneAwareError
コード(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);
}
}
チュートリアル(第3章:サービス)、私はユーザのバックエンドAPIにアクセスすることができませんでしたので、私はNodeJS
(私のネットワーク上のOPi上でホスティング)。私は私のdev compを使って投稿することができ、私はエミュレータのブラウザからGET
リクエストにアクセスすることができますが、私はIP:portをポストしようとするとMalformedURLException
となります。
このURLに投稿するにはどうすればよいですか?すべてのNativescript http.post()
例では、DNSベースのURLを使用できます。 IPベースのリクエストも可能ですか?
あなたは正しいです、魅力的に働いています!私はそれを試していないと信じられない...リンクもありがとう、私はそれを念頭に置くでしょう。 – Mislarieth