невозможно выполнить запрос - ответ - PullRequest
0 голосов
/ 23 августа 2011

Я написал следующий код для связи клиент-сервер в Blackberry, но он не работает.

Я отправляю данные через POST.

Я не получаю ответа от сервера во время тестирования с использованием симулятора Blackberry.

С Android и iPhone я могу получитьответ от того же URL сервера и с теми же параметрами запроса.

private void communicate() {

         HttpConnection hc = null; 
         DataInputStream dis = null;
         DataOutputStream dos = null;
         StringBuffer messagebuffer = new StringBuffer();
         try{
         String input="firstname="+ fName.getText().trim()+
         "&lastname=" + lName.getText().trim()+"&platform=blackberry";
         String url = "http://127.0.0.1:80/index/login";

         hc = (HttpConnection)
         Connector.open(url, Connector.READ_WRITE); // Set the request method
         hc.setRequestMethod(HttpConnection.POST);
         hc.setRequestProperty("User-Agent", "BlackBerry");
         hc.setRequestProperty("Content-Type",
         "application/x-www-form-urlencoded");
         hc.setRequestProperty("Content-Length",
         Integer.toString(input.length()));

         dos = hc.openDataOutputStream();
         dos.write(input.getBytes());
         dos.flush(); dos.close();
         // Retrieve the response back from the servlet
         dis = new DataInputStream(hc.openInputStream());
         int ch;
         // Check the Content-Length first
         long len = hc.getLength();
         if(len!=-1) {
         for(int i = 0;i<len;i++)

         if((ch = dis.read())!= -1)
         messagebuffer.append((char)ch);
         } else { // if the content-length is not available
         while ((ch = dis.read()) != -1)
         messagebuffer.append((char) ch);
         }
         dis.close();
         }catch(Exception e){
         e.printStackTrace();
         }
}

Пожалуйста, предложите, если мне нужно внести какие-либо изменения в код.

Заранее спасибо.

CB

1 Ответ

1 голос
/ 23 августа 2011

Сервер MDS не разрешит подключение к 127.0.0.1 или локальному хосту.

...