2012-03-01 108 views
1

我试图从J2MEHTTP删除请求中J2ME

发送Rails的服务器上删除请求

输出是

STATUS: 422 

和元素不会被删除。

下面的代码:

HttpConnection hc = null; 
    InputStream istrm = null; 
    String msg = "_method=DELETE"; 
    System.out.println(id); 
    try { 
     hc = (HttpConnection) Connector.open(server + "documents/" + id + ".xml"); 
     hc.setRequestMethod(HttpConnection.POST); 
     hc.setRequestProperty("Content-type", "application/x-www-form-urlencoded"); 
     hc.setRequestProperty("Content-length", "" + msg.getBytes().length); 

     OutputStream out = hc.openOutputStream(); 
     out.write(msg.getBytes()); 
     out.close(); 

     System.out.println("STATUS: " + hc.getResponseCode()+ hc.getResponseMessage()); 

回答

0

关闭的OutputStream

int res_code=hc.getResponseCode(); 
if(res_code==HttpConnection.HTTP_OK) 
{ 
//Success 
} 
else 
{ 
//Failure 
} 
......... 
//After performing all operations then close streams and connection 
out.close(); 
hc.close(); 

尝试it.All最好

之前添加以下语句