سؤال

يمكنني استخدام هذا الرمز للقيام بطلب httpget إلى خادم الويب الخاص بي.إنه يعمل بشكل جيد على المحاكي ولكن ليس في شعور HTC الخاص بي.الانتهاء فقط من دون القيام بطلب HTTP.أي فكرة؟ giveacodicetagpre.

هل كانت مفيدة؟

المحلول

While your approach is correct and will work, it's much easier to use the EntityUtils helper class to retrieve the response body as a string. Simply:

String body = EntityUtils.toString(httpEntity);

نصائح أخرى

There was no exception nor warning in stacktrace. Only memory allocation messages. Anyway i solved it by using URLConnection instead of HttpClient :

try {
      URL url = new URL(urlstring);
      URLConnection connection = url.openConnection();
      InputStream inputStream = connection.getInputStream();
      BufferedInputStream bufferedInput = new BufferedInputStream(inputStream);

    // Read the response into a byte array
      ByteArrayBuffer byteArray = new ByteArrayBuffer(50);
      int current = 0;
      while((current = bufferedInput.read()) != -1){
            byteArray.append((byte)current);
      }

      // Construct a String object from the byte array containing the response
     resultStr = new String(byteArray.toByteArray());
    } catch (Exception e) {
      e.printStackTrace();
    }

For some reason it worked. Still trying to figure what went wrong.

مرخصة بموجب: CC-BY-SA مع الإسناد
لا تنتمي إلى StackOverflow
scroll top