Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/android/198.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Android 是否将示例url转换为具有标头的http请求?_Android_Http Headers_Httprequest - Fatal编程技术网

Android 是否将示例url转换为具有标头的http请求?

Android 是否将示例url转换为具有标头的http请求?,android,http-headers,httprequest,Android,Http Headers,Httprequest,我想在android中将给定的url转换为HTTP请求 旋度-v "" --标题“授权:持票人” Atza | IQEBLJASAHQ5ZX7PKP9PCGCY6T1JKQJHOEZPWIUQM“ 我尝试了几种方法,但都是心照不宣,请你解释一下。把你尝试过的贴出来,谢谢,我自己做的 public static final String URL = "https://cdws.us-east-1.amazonaws.com/drive/v1/nodes?filters=kind:F

我想在android中将给定的url转换为HTTP请求

旋度-v "" --标题“授权:持票人” Atza | IQEBLJASAHQ5ZX7PKP9PCGCY6T1JKQJHOEZPWIUQM“


我尝试了几种方法,但都是心照不宣,请你解释一下。

把你尝试过的贴出来,谢谢,我自己做的
        public static final String URL = "https://cdws.us-east-1.amazonaws.com/drive/v1/nodes?filters=kind:FILE";


        HttpClient httpclient = new DefaultHttpClient();
        HttpGet request = new HttpGet(URL);
        String result = null;
        request.addHeader("Authorization", "Bearer " + authcode);
        //auth code is the code u get by Login on amazon link is http://login.amazon.com/android
        try {
            HttpResponse httpResponse = httpclient.execute(request);
            HttpEntity entity = httpResponse.getEntity();

            if (entity != null) {

                // A Simple JSON Response Read
                InputStream instream = entity.getContent();
                result = convertStreamToString(instream);
                // now you have the string representation of the HTML
                // request
                Log.d("RESPONSE: ", result);
                instream.close();

            }

        } catch (ClientProtocolException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        } catch (IOException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        }

        private static String convertStreamToString(InputStream is) {

    BufferedReader reader = new BufferedReader(new InputStreamReader(is));
    StringBuilder sb = new StringBuilder();

    String line = null;
    try {
        while ((line = reader.readLine()) != null) {
            sb.append(line + "\n");
        }
    } catch (IOException e) {
        e.printStackTrace();
    } finally {
        try {
            is.close();
        } catch (IOException e) {
            e.printStackTrace();
        }
    }
    return sb.toString();
}