0

我开发了一个 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();
    }
}
4

0 回答 0