Http-Duplicate数据上传到服务器

时间:2013-06-25 06:26:45

标签: android

我开发了一个Android应用程序,它使用http连接将数据同步到服务器 但遗憾的是,重复的数据会被提交到服务器,有时还会将截断的数据传递给服务器。

如果有人解决我的问题,请帮助我

我正在使用以下代码

{
    URL url = new URL(urlStr);
    URLConnection urlConn = url.openConnection();
    if (!(urlConn instanceof HttpURLConnection)) {
        throw new IOException ("URL is not an Http URL");
    }
    HttpURLConnection httpConn = (HttpURLConnection)urlConn;
    httpConn.setAllowUserInteraction(false);
    httpConn.setInstanceFollowRedirects(true);
    httpConn.setRequestMethod("POST");
    httpConn.setRequestProperty("Content-Type", 
        "application/x-www-form-urlencoded");
    httpConn.setRequestProperty("Content-Length", "" + 
    Integer.toString(urlParameters.getBytes().length));
    httpConn.setRequestProperty("Content-Language", "en-US");
    httpConn.setConnectTimeout(1000);
    httpConn.connect(); 
    DataOutputStream wr = new DataOutputStream (
    httpConn.getOutputStream ());
    wr.writeBytes (urlParameters);
    wr.flush ();
    wr.close ();
    resCode = httpConn.getResponseCode(); 
    if (resCode == HttpURLConnection.HTTP_OK) {
        in = httpConn.getInputStream();
    }
}

0 个答案:

没有答案