简体   繁体   English

HTTP 请求无响应

[英]No response from HTTP request

i have written an android app which post data to my database.我编写了一个将数据发布到我的数据库的 android 应用程序。 The app should access an webservice which post the data to the database.该应用程序应访问将数据发布到数据库的网络服务。 the webservice works fine.网络服务工作正常。 ive testet it with my browser, he is already on the server.我用我的浏览器测试过,他已经在服务器上了。 now i want my app to execute the webservice.现在我希望我的应用程序执行网络服务。 but that doesnt work.但这不起作用。 My debugger doesnt work too so im not able to debug.我的调试器也不起作用,所以我无法调试。 here is my code to for accessing the webservice.这是我用于访问网络服务的代码。 any ideas??有任何想法吗??

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());
    }


}

} }

The Class is called from my main Activity by该类是从我的主要活动中调用的

new PostBlog(insertBlogURL).execute("");

Is there another easier way to execute my ".jsp?asdd=sdsd" file on the server?是否有另一种更简单的方法在服务器上执行我的“.jsp?asdd=sdsd”文件?

Thanks for your ideas.谢谢你的想法。

Instead of doing :而不是做:

new PostBlog(insertBlogURL).execute("");

Change your constructor and retrieve the url from the doInBackground method, by doing params[0]通过执行params[0]更改构造函数并从doInBackground方法中检索 url

Then initiate the download like this然后像这样启动下载

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

I should say this is a modified snippet of code from my own project, so it might not work exactly the way you expect.我应该说这是我自己项目中修改后的代码片段,因此它可能无法完全按照您的预期工作。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM