gpt4 book ai didi

android - 将示例 url 转换为带有 header android 的 http 请求?

转载 作者:行者123 更新时间:2023-11-29 00:12:52 25 4
gpt4 key购买 nike

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

curl -v“https://cdws.us-east-1.amazonaws.com/drive/v1/nodes?filters=kind:FILE”--header "授权:不记名Atza|IQEBLjAsAhQ5zx7pKp9PCgCy6T1JkQjHHOEzpwIUQM"

我尝试了一些方法,但所有的方法都很好地解释了。

最佳答案

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

关于android - 将示例 url 转换为带有 header android 的 http 请求?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/28959211/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com