HTTP-запрос на удаление в J2ME - PullRequest
1 голос
/ 01 марта 2012

Я пытаюсь отправить запрос на удаление на Rails Server с J2ME

Выход

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());

1 Ответ

0 голосов
/ 14 апреля 2012

Добавьте следующие операторы перед закрытием outputtream

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();

Попробуйте. Все лучшее

...