- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
问题:http.post()
返回
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
编写了自己的 API(托管在我网络上的 OPi 上)。我可以使用我的 dev comp 发布,并且我可以从模拟器的浏览器访问 GET
请求,但是当我尝试发布 IP:port 时,我得到一个 MalformedURLException
.
我如何发布到这个 URL?我能找到的所有 Nativescript http.post()
示例都使用基于 DNS 的 URL;甚至可以进行基于 IP 的请求吗?
最佳答案
是的,可以使用基于 IP 的请求。但是,您需要提供 http://
前缀,并且在通过模拟器工作时,您应该考虑环回地址与您的开发机器上的地址不同
当使用 Android AVD 时,环回地址是 10.0.2.2
(对于 GenyMotio,环回是不同的),而在 iOS 上,环回是 localhost
。因此,如果您想使用本地 IP 地址,则需要考虑到这一点。
例如here
关于android - IP 地址的 Nativescript http.post() MalformedURLException,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/45092739/
我希望程序打印出每个网址的文本 HtmlPage points = (HtmlPage) webClient.getPage("https://www.hockey-reference.com/lea
我有以下代码片段: public class DOMTest { public static void main( String[] args ) throws Par
该程序假设调用以下 URL http://www.google.com当选择退出时,所有其他按钮都工作正常,但是当我单击“退出”时没有任何反应。 我还得到: warning: unreachable
我正在尝试从 HTMLUnit tutorial 执行此代码: final WebClient webClient = new WebClient(); final HtmlPage page = w
我的 friend 让我在这里发布他的问题,问题就在这里: 我有一个问题...我的代码运行得很好,突然出现了一个错误。我不知道它有什么问题,也许你们可以告诉我一些我正在犯的明显错误。 那是错误的沟通:
网络逻辑 11g (10.3.5) Spring 框架 3.1.3 Spring 网络服务 2.1.1 在 Weblogic 上运行的 Spring-ws Web 服务。相同的 Web 服务在 Tom
我正在进行应用程序测试并发现了一个问题。我的应用程序。在里面有一个 authenticate(email, password) Action 安全 Controller ,当从登录页面调用时,带有有效
我正在配置 SymmetricDS 3.6.12 的两个实例。服务器实例在 Glassfish 3 服务器中工作,使用 8181 端口作为 https。客户端实例作为服务运行(在 jetty 中),h
我写了一个简单的程序,它在我的书中。但我收到 MalformedURLException 异常。这是我的代码 import java.net.URL; import javax.swing.Image
我将 Windows 从 7 升级到 10,现在在我的项目中,我在运行测试时遇到了这些异常。 这是我的代码 @BeforeClass public static void createSche
实例化新 URL 时,DrawImage 类中的下面第一段代码起作用。但是,当我从另一个类 RandomImage 输入相同的字符串(“https://www.purchased.com/hubfs/
我试图在我的代码中引发 MalformedURLException 来测试我对它的处理,但是无论我尝试什么,我似乎都无法引起它。 (我传入了一个完整的无意义的非 url 字符串,但它仍然没有出现,我只
我使用了以下代码: g.drawImage(Toolkit.getDefaultToolkit().createImage(new URL(".\\mouseicon1.bmp")), MouseX
我的意思是,Java 如何决定哪些协议(protocol)可用?我从 Eclipse 内部运行一些代码,它工作得很好。然后我从 Eclipse 外部运行相同的代码,并得到“未知协议(protocol)
如何解决这个问题?有什么帮助吗? ERROR : java.net.MalformedURLException: Protocol not found: /mnt/sdcard/EREADER/New
如果 url 路径中有 http,为什么我得不到协议(protocol)? 日志: network: Connecting http://xxx.ccc.local/upload/up.php?aa=
我正在编写一个类以在 Java 中运行 xjc。我的代码如下: URL url = new URL("C:\\Users\\Simran\\Desktop\\books.xsd"); Schema
public class AnalyticsDetectLanguage { static String subscription_key_var; static String sub
所以我正在开发浏览器(正当理由),但我不断收到 java.net.MalformedURLException。我正在尝试将 JEditorPane 的页面设置为从我的计算机加载的文件。代码如下:
我正在尝试解析 xml,但出现错误。 公共(public)静态字符串xmlVersion(字符串源){ try { DocumentBuilderFactory documentBuilder
我是一名优秀的程序员,十分优秀!