1

我正在编写一个应用程序,其中我使用 Http Connection 在服务器上发布数据。当我在模拟器中检查它时,我的应用程序运行良好。我的 Web 服务花费了太多时间来生成响应,并且我的模拟器也以正确的方式响应。不知何故,当我在设备上安装应用程序时,我的应用程序在服务器上发布了两次数据。我已经检查过了......有没有人有任何关于如何摆脱这种情况的解决方案???

在这里,我附上了我的发送请求代码。我认为移动应用程序在达到 HTTP 超时时正在发送另一个请求,但我不知道是什么问题。请帮我。

String param=
   "function=OpenRecharge&LoginId="+SharedVariable.getUserInfo().getLoginID()
              +"&BatchId="+SharedVariable.getSelectedProduct().getBatchID()
              +"&SystemServiceID="+SharedVariable.getSelectedProduct().getSystemServiceID()
              +"&ReferalNumber="+strMobileNo
              +"&Amount="+strAmount
              +"&FromANI="+fromMoNo
              +"&Email="
              +"&Checksum="+Checksum;
System.out.println("Final Parameter:\n"+param);

connection = (HttpConnection) Connector.open(url);

//Connector.open(param, strAmount, quit)
connection.setRequestMethod(HttpConnection.POST);
connection.setRequestProperty("User-Agent", "Profile/MIDP-1.0 Configuration/CLDC-1.0");
connection.setRequestProperty("Accept_Language","en-US");
connection.setRequestProperty("Content-Type", "application/x-www-form-urlencoded");

OutputStream out = connection.openOutputStream();
out.write(param.getBytes());

out.flush();
//System.out.println("Status Line Code: " + connection.getResponseCode());
//System.out.println("Status Line Message: " + connection.getResponseMessage());

is=connection.openDataInputStream();
int chr;
StringBuffer sb=new StringBuffer();
while ((chr = is.read()) != -1)
    sb.append((char) chr);

System.out.println("Response===>"+sb.toString());
4

2 回答 2

1

我不是应用程序开发人员,无论如何,您的网络服务不应该有很大的响应延迟。我认为这是你的问题,你应该解决它。制作缓存或预处理您的响应。

尽管您可以更改超时时间(似乎是固定的),但不推荐这样做,因为许多移动(wap)代理的超时时间为 30 秒。

于 2012-02-28T19:12:24.653 回答
1

您能否使用“处理中...”之类的占位符文本提供答案,然后在延迟后让网络浏览器重试?

于 2012-05-28T14:47:37.850 回答