2

我正在尝试创建一个简单的 android 应用程序,它将与网站进行通信。我遇到的问题是,每次我尝试使用 HttpPost Eclipse 的调试器时都会告诉我: S​​ource not Found The JAR file C:\Users...\android-sdk\plarforms\android-16\android.jar has no源附件 您可以通过单击下面的附加源来附加源:

我试图附加一些 jar 文件,但没有任何效果。这是我的代码:

    public void onClick(View v) {

    URI website = null;
    HttpResponse response = null;
    BufferedReader in = null;


    HttpClient client = new DefaultHttpClient();

    try {
        website = new URI("http://fakewebsite.php");
    } catch (URISyntaxException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    }

    HttpGet getRequest = new HttpGet();
    getRequest.setURI(website);

    HttpPost postRequest = new HttpPost();

    try {
        response = client.execute(postRequest);
    } catch (ClientProtocolException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    } catch (IOException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    }

}

感谢您的任何帮助

4

1 回答 1

0

利用

 response = client.execute(getRequest);

代替

 response = client.execute(postRequest);

您收到此错误是因为您当前未设置 URI

HttpPost postRequest = new HttpPost();

于 2012-10-12T22:37:09.627 回答