在 Android 应用程序中设置 URL?

Setting URL in an Android application?

在我的 Android 应用程序中,我想连接到 server/web 主机上的 PHP 文件。目前我不能 POST 数据到 PHP 文件,我想我正在以 不正确的格式 传递 URL。

以 Google URL 为例,建立我的 PHP 文件的路径是否正确?

URL url = new URL("http://74.125.224.72/myFile.php");

您的 URL

中似乎多了一个 space
URL url = new URL("http://74.125.224.72 /myFile.php");

必须

URL url = new URL("http://74.125.224.72/myFile.php");

EDIT 您还可以使用 android Uri class 并使用 Uri.Builder

Uri uri = new Uri.Builder()
    .scheme("http")
    .authority("74.125.224.72")
    .appendPath("myFile.php")
    .build();