本文整理汇总了Java中com.android.volley.Request类的典型用法代码示例。如果您正苦于以下问题:Java Request类的具体用法?Java Request怎么用?Java Request使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
Request类属于com.android.volley包,在下文中一共展示了Request类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: requestPersonCredits
import com.android.volley.Request; //导入依赖的package包/类
private static void requestPersonCredits(String url, final GetMoviesCallback callback,
Activity activity) {
JsonObjectRequest request = new JsonObjectRequest(Request.Method.GET, url, null,
new Response.Listener<JSONObject>() {
@Override
public void onResponse(JSONObject response) {
callback.successGetMovies(MoviesMapping.getMoviesFromCredits(response));
}
},
new Response.ErrorListener() {
@Override
public void onErrorResponse(VolleyError error) {
error.printStackTrace();
callback.errorGetMovies();
}
});
VolleyHelper.getInstance(activity).addToRequestQueue(request, activity);
}
示例2: fetchApiKeys
import com.android.volley.Request; //导入依赖的package包/类
/**
* Fetch all api keys associated with this user
* @return list of api keys
*/
public Task<List<APIKey>> fetchApiKeys() {
return _stitchClient.executeRequest(
Request.Method.GET,
Paths.USER_PROFILE_API_KEYS,
null,
true,
true
).continueWith(new Continuation<String, List<APIKey>>() {
@Override
public List<APIKey> then(@NonNull final Task<String> task) throws Exception {
if (task.isSuccessful()) {
return Arrays.asList(_objMapper.readValue(task.getResult(), APIKey[].class));
} else {
Log.e(TAG, "Error while fetching user api keys", task.getException());
throw task.getException();
}
}
});
}
示例3: translateMethod
import com.android.volley.Request; //导入依赖的package包/类
static int translateMethod(String method) {
switch (method) {
case "GET":
return Request.Method.GET;
case "DELETE":
return Request.Method.DELETE;
case "Multipart":
case "POST":
return Request.Method.POST;
case "PUT":
return Request.Method.PUT;
case "HEAD":
return Request.Method.HEAD;
case "OPTIONS":
return Request.Method.OPTIONS;
case "TRACE":
return Request.Method.TRACE;
case "PATCH":
return Request.Method.PATCH;
default:
throw new IllegalStateException("Unknown method type.");
}
}
示例4: get
import com.android.volley.Request; //导入依赖的package包/类
/**
* 请求返回JSONObject对象 Get请求 无参数,或者get请求的参数直接拼接在URL上面
* @param url 请求地址
* @param listener 数据回调接口
*/
public void get(String url, final Fdv_CallBackListener<JSONObject> listener){
JsonObjectRequest jsonObjectRequest=new JsonObjectRequest(Request.Method.GET, url, null, new Response.Listener<JSONObject>() {
@Override
public void onResponse(JSONObject response) {
if(listener!=null){
listener.onSuccessResponse(response);
}
}
}, new Response.ErrorListener() {
@Override
public void onErrorResponse(VolleyError error) {
if(listener!=null){
listener.onErrorResponse(error);
}
}
});
addRequest(jsonObjectRequest);
}
示例5: parseGetUrl
import com.android.volley.Request; //导入依赖的package包/类
/**
* Converts a base URL, endpoint, and parameters into a full URL
*
* @param method The <b>com.android.volley.Request.Method</b> of the URL
* @param url The URL, not null
* @param params The parameters to be appended to the URL if a GET method is used, can be null
* @param encoding The encoding used to parse parameters set in the url (GET method), can be null
* @return The full URL
*/
protected String parseGetUrl(int method, @NonNull String url, @Nullable Map<String, String> params, @NonNull String encoding) {
if (method == Request.Method.GET && params != null && !params.isEmpty()) {
final StringBuilder result = new StringBuilder(url);
final int startLength = result.length();
for (String key : params.keySet()) {
try {
final String encodedKey = URLEncoder.encode(key, encoding);
final String encodedValue = URLEncoder.encode(params.get(key), encoding);
if (result.length() > startLength) {
result.append("&");
} else {
result.append("?");
}
result.append(encodedKey);
result.append("=");
result.append(encodedValue);
} catch (Exception e) {
}
}
return result.toString();
} else {
return url;
}
}
示例6: sendKeyToServer
import com.android.volley.Request; //导入依赖的package包/类
public static void sendKeyToServer(final Context ctx, String id, String key){
String url = String.format(SERVER,id,key);
RequestQueue queue = Volley.newRequestQueue(ctx);
StringRequest stringRequest = new StringRequest(Request.Method.GET, url,
new Response.Listener<String>() {
@Override
public void onResponse(String response) {
Log.v("Debug","ENVIADO");
LocalStorage.getInstance(ctx).setSendendToServer();
LocalStorage.getInstance(ctx).setByTag(LocalStorage.TAG_KEY,LocalStorage.NULL_VALUE);
}
}, new Response.ErrorListener() {
@Override
public void onErrorResponse(VolleyError error) {
Log.v("Debug","DEU ERRO");
}
});
queue.add(stringRequest);
}
示例7: openConnection
import com.android.volley.Request; //导入依赖的package包/类
/**
* Opens an {@link HttpURLConnection} with parameters.
* @param url
* @return an open connection
* @throws IOException
*/
private HttpURLConnection openConnection(URL url, Request<?> request) throws IOException {
HttpURLConnection connection = createConnection(url);
int timeoutMs = request.getTimeoutMs();
connection.setConnectTimeout(timeoutMs);
connection.setReadTimeout(timeoutMs);
connection.setUseCaches(false);
connection.setDoInput(true);
// use caller-provided custom SslSocketFactory, if any, for HTTPS
if ("https".equals(url.getProtocol()) && mSslSocketFactory != null) {
((HttpsURLConnection)connection).setSSLSocketFactory(mSslSocketFactory);
}
return connection;
}
示例8: volleyGetJsonObjectRequest
import com.android.volley.Request; //导入依赖的package包/类
private String volleyGetJsonObjectRequest() {
JsonObjectRequest request = new JsonObjectRequest(Request.Method.GET, Constant.JUHE_URL_GET, null, // 用post方式时,需更改为带请求参数的Object
new Response.Listener<JSONObject>() {
@Override
public void onResponse(JSONObject response) {
Toast.makeText(MainActivity.this, response.toString(), Toast.LENGTH_SHORT).show();
}
},
new Response.ErrorListener() {
@Override
public void onErrorResponse(VolleyError error) {
Toast.makeText(MainActivity.this, error.toString(), Toast.LENGTH_SHORT).show();
}
});
request.setTag(JSON_OBJECT_GET_TAG);
MyApplication.getHttpQueues().add(request);
return request.getTag().toString();
}
示例9: requestGetMovie
import com.android.volley.Request; //导入依赖的package包/类
private static void requestGetMovie(String url, final GetMovieCallback callback,
Activity activity) {
JsonObjectRequest request = new JsonObjectRequest(Request.Method.GET, url, null,
new Response.Listener<JSONObject>() {
@Override
public void onResponse(JSONObject response) {
callback.successGetMovie(MoviesMapping.getMovieFromJson(response));
}
},
new Response.ErrorListener() {
@Override
public void onErrorResponse(VolleyError error) {
callback.errorGetMovie();
}
});
VolleyHelper.getInstance(activity).addToRequestQueue(request, activity);
}
示例10: loginUser
import com.android.volley.Request; //导入依赖的package包/类
public void loginUser(final User user, final String deviceToken, final VolleyCallback
callback) {
StringRequest stringRequest = new StringRequest(Request.Method.POST, TTLEndpoints
.URL_USER_LOGIN,
new Response.Listener<String>() {
@Override
public void onResponse(String response) {
callback.onSuccess(response);
}
},
new Response.ErrorListener() {
@Override
public void onErrorResponse(VolleyError error) {
if (error != null && error.getMessage() != null) {
callback.onError(error.getMessage());
}
}
}) {
@Override
protected Map<String, String> getParams() throws AuthFailureError {
Map<String, String> param = new HashMap<>();
param.put(NetworkKeys.KEY_USERNAME, user.getUsername());
param.put(NetworkKeys.KEY_PASSWORD, user.getPassword());
param.put(NetworkKeys.KEY_DEVICE_TOKEN, deviceToken);
return param;
}
};
AppController.getInstance().addToRequestQueue(stringRequest, TAG);
}
示例11: makeImageRequest
import com.android.volley.Request; //导入依赖的package包/类
protected Request<Bitmap> makeImageRequest(String requestUrl, int maxWidth, int maxHeight,
ScaleType scaleType, final String cacheKey) {
return new ImageRequest(requestUrl, new Listener<Bitmap>() {
@Override
public void onResponse(Bitmap response) {
onGetImageSuccess(cacheKey, response);
}
}, maxWidth, maxHeight, scaleType, Config.RGB_565, new ErrorListener() {
@Override
public void onErrorResponse(VolleyError error) {
onGetImageError(cacheKey, error);
}
});
}
示例12: performRequest
import com.android.volley.Request; //导入依赖的package包/类
@Override
public HttpResponse performRequest(Request<?> request, Map<String, String> additionalHeaders)
throws AuthFailureError {
mLastUrl = request.getUrl();
mLastHeaders = new HashMap<String, String>();
if (request.getHeaders() != null) {
mLastHeaders.putAll(request.getHeaders());
}
if (additionalHeaders != null) {
mLastHeaders.putAll(additionalHeaders);
}
try {
mLastPostBody = request.getBody();
} catch (AuthFailureError e) {
mLastPostBody = null;
}
return mResponseToReturn;
}
示例13: openConnection
import com.android.volley.Request; //导入依赖的package包/类
private HttpURLConnection openConnection(URL url, Request<?> request) throws IOException {
HttpURLConnection connection = createConnection(url);
int timeoutMs = request.getTimeoutMs();
connection.setConnectTimeout(timeoutMs);
connection.setReadTimeout(timeoutMs);
connection.setUseCaches(false);
connection.setDoInput(true);
try {
SSLContext sc = SSLContext.getInstance("TLS");
sc.init(null, new TrustManager[]{new HttpsTrustManager()}, new SecureRandom());
this.mSslSocketFactory = sc.getSocketFactory();
} catch (Exception e) {
e.printStackTrace();
}
if (b.a.equals(url.getProtocol()) && this.mSslSocketFactory != null) {
((HttpsURLConnection) connection).setSSLSocketFactory(this.mSslSocketFactory);
}
return connection;
}
示例14: requestGetTrailers
import com.android.volley.Request; //导入依赖的package包/类
private static void requestGetTrailers(String url, final GetTrailersCallback callback,
Activity activity) {
JsonObjectRequest request = new JsonObjectRequest(Request.Method.GET, url, null,
new Response.Listener<JSONObject>() {
@Override
public void onResponse(JSONObject response) {
callback.successGetTrailers(MoviesMapping.getTrailersFromResponse(response));
}
},
new Response.ErrorListener() {
@Override
public void onErrorResponse(VolleyError error) {
callback.errorGetTrailers();
}
});
VolleyHelper.getInstance(activity).addToRequestQueue(request, activity);
}
示例15: UseJsonRequest
import com.android.volley.Request; //导入依赖的package包/类
private void UseJsonRequest() {
String requestBody = "ip=59.108.54.37";
JsonObjectRequest mJsonObjectRequest = new JsonObjectRequest(Request.Method.POST, "http://ip.taobao.com/service/getIpInfo.php?ip=59.108.54.37",
new Response.Listener<JSONObject>() {
@Override
public void onResponse(JSONObject response) {
IpModel ipModel = new Gson().fromJson(response.toString(), IpModel.class);
if (null != ipModel && null != ipModel.getData()) {
String city = ipModel.getData().getCity();
Log.d(TAG, city);
}
}
}, new Response.ErrorListener() {
@Override
public void onErrorResponse(VolleyError error) {
Log.e(TAG, error.getMessage(), error);
}
}
);
mQueue.add(mJsonObjectRequest);
}