2012-02-27 57 views
1

我在写一个应用程序,我正在使用Http连接在服务器上发布数据。当我在模拟器中检查它时,我的应用程序工作正常。我的Web服务花费太多时间来生成响应,我的模拟器也以正确的方式响应。不知何故,当我在设备上安装应用程序时,我的应用程序在服务器上发布了两次数据。我检查了它...有没有人有任何解决方案如何摆脱这?HTTP连接发布数据两次

在这里,我附上了我的发送请求的代码。我认为移动应用程序在达到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()); 
+1

我强烈怀疑这是因为您在onCreate和onResume中都有相同的代码。 – kosa 2012-02-27 21:19:05

+0

没有一个更全面的代码引用我会同意thinksteep的评论尽可能原因 – Kerry 2012-02-27 22:33:31

+0

@thinksteep:好友..这是j2me代码..不是一个Android代码,.. – 2012-02-28 06:24:36

回答

1

你能提供一个像“处理...”等占位符文本的答案,然后延迟之后,Web浏览器再试一次吗?

+0

问题已解决我的朋友.. – 2012-05-29 07:48:01

+0

@NiravBhandari,很好听。 :-) – 2012-05-29 07:58:33

1

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

虽然你可以改变超时时间(这看起来是固定的),但不建议让许多移动(wap)代理超时30秒。