Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/android/234.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/sql-server-2005/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java HTTP请求没有响应_Java_Android - Fatal编程技术网

Java HTTP请求没有响应

Java HTTP请求没有响应,java,android,Java,Android,我已经编写了一个android应用程序,可以将数据发布到我的数据库中。应用程序应该访问将数据发布到数据库的Web服务。Web服务运行良好。我用我的浏览器测试了一下,他已经在服务器上了。现在我想让我的应用程序执行Web服务。但这不起作用。我的调试器不工作,所以我无法调试。这是我访问Web服务的代码。有什么想法吗 public class PostBlog extends AsyncTask<String, Void, String> { String BlogURL; public

我已经编写了一个android应用程序,可以将数据发布到我的数据库中。应用程序应该访问将数据发布到数据库的Web服务。Web服务运行良好。我用我的浏览器测试了一下,他已经在服务器上了。现在我想让我的应用程序执行Web服务。但这不起作用。我的调试器不工作,所以我无法调试。这是我访问Web服务的代码。有什么想法吗

public class PostBlog extends AsyncTask<String, Void, String> {
String BlogURL;

public PostBlog(String insertBlogURL) {
    BlogURL = insertBlogURL;
}

@Override
protected String doInBackground(String... params) {
    postBlogData(BlogURL);
    return null;
}

public void postBlogData(String url) {

    String result = "";
    //the year data to send
    ArrayList<NameValuePair> nameValuePairs = new ArrayList<NameValuePair>();
    nameValuePairs.add(new BasicNameValuePair("year", "1980"));

    //http post
    try {
        HttpClient httpclient = new DefaultHttpClient();
        HttpPost httppost = new HttpPost(url);
        httppost.setEntity(new UrlEncodedFormEntity(nameValuePairs));
        HttpResponse response = httpclient.execute(httppost);
        HttpEntity entity = response.getEntity();
        InputStream is = entity.getContent();
        BufferedReader reader = new BufferedReader(new InputStreamReader(is, "iso-8859-1"), 8);
        StringBuilder sb = new StringBuilder();
        String line = null;
        while ((line = reader.readLine()) != null) {
            sb.append(line + "\n");
        }
        is.close();

        result = sb.toString();
    } catch (Exception e) {

        //(TextView)rootView.findViewById(R.id.question)
        Log.e("log_tag", "Error converting result " + e.toString());
    }


}
是否有其他更简单的方法在服务器上执行我的“.jsp?asdd=sdsd”文件

谢谢你的建议。

不要做:

newpostblog(insertBlogURL)。执行(“”)

通过执行
params[0]

然后像这样开始下载

PostBlog blogPoster = new PostBlog();
try {
    blogPoster.execute(insertBlogURL);
} catch (InterruptedException e) {} catch (ExecutionException e) {}

我应该说这是我自己项目中修改过的代码片段,因此它可能无法完全按照您期望的方式工作。

如果您无法调试应用程序,只需添加日志即可。并告诉我们日志内容。如何添加日志以及在何处添加日志?在每一行之后,你不确定它会产生什么结果。如果你在学习android,你最好和调试器相处。如果你不能理解你的问题是什么,那么在stackoverflow上发布问题是没有帮助的。你能写下更改后的构造函数应该是什么样子吗?为什么要在一次尝试中添加两个异常?编译器显示了错误4。谢谢。@TheAlgorithm上帝将您的构造函数全部删除,您不需要它。在后台,不要将
BlogURL
传递给
postBlogData
方法,而是传递
params[0]
@算法如果我捕捉到两个错误,那么准确地说,你当然可以捕捉到一个常规的
异常
,但是你不能准确地判断出发生了哪一个错误,在不了解编译器错误的情况下,我无法为您提供很多帮助,尽管我建议您自己处理它们,因为它们可能是语法问题
PostBlog blogPoster = new PostBlog();
try {
    blogPoster.execute(insertBlogURL);
} catch (InterruptedException e) {} catch (ExecutionException e) {}