本文整理汇总了Java中com.yanzhenjie.nohttp.rest.Request类的典型用法代码示例。如果您正苦于以下问题:Java Request类的具体用法?Java Request怎么用?Java Request使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
Request类属于com.yanzhenjie.nohttp.rest包,在下文中一共展示了Request类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: GetEncHtml
import com.yanzhenjie.nohttp.rest.Request; //导入依赖的package包/类
static String GetEncHtml(String url, String text, boolean needCookie) {
try {
String param = encryptedRequest(text);
Request<String> request = NoHttp.createStringRequest(url, RequestMethod.POST);
request.addHeader("User-Agent", "Mozilla/5.0 (Windows NT 10.0; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/45.0.2454.101 Safari/537.36");
if (needCookie) {
request.addHeader("Cookie", "__remember_me=true; MUSIC_U=5f9d910d66cb2440037d1c68e6972ebb9f15308b56bfeaa4545d34fbabf71e0f36b9357ab7f474595690d369e01fbb9741049cea1c6bb9b6; __csrf=8ea789fbbf78b50e6b64b5ebbb786176; os=uwp; osver=10.0.10586.318; appver=1.2.1; deviceId=0e4f13d2d2ccbbf31806327bd4724043");
}
request.setDefineRequestBody(param, "application/x-www-form-urlencoded");
Response execute;
execute = NoHttp.startRequestSync(request);
if (execute.isSucceed()) {
return execute.get().toString();
}
} catch (Exception ignored) {
}
return "";
}
示例2: GetHtmlContent
import com.yanzhenjie.nohttp.rest.Request; //导入依赖的package包/类
static String GetHtmlContent(String url, boolean needCookie) {
try {
Request<String> request = NoHttp.createStringRequest(url, RequestMethod.GET);
request.addHeader("User-Agent", "Mozilla/5.0 (Windows NT 10.0; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/45.0.2454.101 Safari/537.36");
if (needCookie) {
request.addHeader("Cookie", "__remember_me=true; MUSIC_U=5f9d910d66cb2440037d1c68e6972ebb9f15308b56bfeaa4545d34fbabf71e0f36b9357ab7f474595690d369e01fbb9741049cea1c6bb9b6; __csrf=8ea789fbbf78b50e6b64b5ebbb786176; os=uwp; osver=10.0.10586.318; appver=1.2.1; deviceId=0e4f13d2d2ccbbf31806327bd4724043");
}
Response execute = NoHttp.startRequestSync(request);
if (execute.isSucceed()) {
return execute.get().toString();
}
} catch (Exception ignored) {
}
return "";
}
示例3: GetHtmlWithRefer
import com.yanzhenjie.nohttp.rest.Request; //导入依赖的package包/类
static String GetHtmlWithRefer(String url, String refer) {
try {
Request<String> request = NoHttp.createStringRequest(url, RequestMethod.GET);
request.addHeader("User-Agent", "Mozilla/5.0 (Windows NT 10.0; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/45.0.2454.101 Safari/537.36");
request.addHeader("Referer", refer);
Response execute = NoHttp.startRequestSync(request);
if (execute.isSucceed()) {
return execute.get().toString();
}
} catch (Exception ignored) {
}
return "";
}
示例4: GetHtmlWithReferCookie
import com.yanzhenjie.nohttp.rest.Request; //导入依赖的package包/类
static String GetHtmlWithReferCookie(String url, String refer) {
try {
Request<String> request = NoHttp.createStringRequest(url, RequestMethod.GET);
request.removeAllHeader();
request.addHeader("User-Agent", "Mozilla/5.0 (Windows NT 10.0; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/45.0.2454.101 Safari/537.36");
request.addHeader("Referer", refer);
request.addHeader("Accept-Encoding","gzip");
request.addHeader("Cookie","user_from=2;XMPLAYER_addSongsToggler=0;XMPLAYER_isOpen=0;_xiamitoken=123456789;");
Response execute = NoHttp.startRequestSync(request);
if (execute.isSucceed()) {
return execute.get().toString();
}
} catch (Exception ignored) {
}
return "";
}
示例5: PostData
import com.yanzhenjie.nohttp.rest.Request; //导入依赖的package包/类
static String PostData(String url, HashMap<String, String> params) {
try {
Request request = NoHttp.createStringRequest(url, RequestMethod.POST);
request.addHeader("User-Agent", "Mozilla/5.0 (Windows NT 10.0; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/45.0.2454.101 Safari/537.36");
int len = params.size();
if (len <= 0) {
return "";
}
request.add(params);
Response execute = NoHttp.startRequestSync(request);
if (execute.isSucceed()) {
return execute.get().toString();
}
} catch (Exception ignored) {
}
return "";
}
示例6: onActivityCreate
import com.yanzhenjie.nohttp.rest.Request; //导入依赖的package包/类
@Override
protected void onActivityCreate(Bundle savedInstanceState) {
setContentView(R.layout.activity_cacel_demo);
mRequestQueue = NoHttp.newRequestQueue(5);
// 请求1。
Request<String> request1 = NoHttp.createStringRequest(Constants.URL_NOHTTP_JSONOBJECT, RequestMethod.GET);
// 请求2。
Request<String> request2 = NoHttp.createStringRequest(Constants.URL_NOHTTP_JSONOBJECT, RequestMethod.GET);
// 请求3。
Request<String> request3 = NoHttp.createStringRequest(Constants.URL_NOHTTP_JSONOBJECT, RequestMethod.GET);
// 这里添加很多request进去。
// mRequestQueue.add(0, request1, null);
// mRequestQueue.add(1, request2, null);
// mRequestQueue.add(2, request3, null);
}
示例7: onActivityCreate
import com.yanzhenjie.nohttp.rest.Request; //导入依赖的package包/类
@Override
protected void onActivityCreate(Bundle savedInstanceState) {
setContentView(R.layout.activity_cacel_demo);
mRequestQueue = NoHttp.newRequestQueue(5);
// 请求1。
Request<String> request1 = NoHttp.createStringRequest(Constants.URL_NOHTTP_JSONOBJECT, RequestMethod.GET);
request1.setCancelSign(cancelSign);
// 请求2。
Request<String> request2 = NoHttp.createStringRequest(Constants.URL_NOHTTP_JSONOBJECT, RequestMethod.GET);
request2.setCancelSign(cancelSign);
// 请求3。
Request<String> request3 = NoHttp.createStringRequest(Constants.URL_NOHTTP_JSONOBJECT, RequestMethod.GET);
request3.setCancelSign(cancelSign);
// 这里添加很多request进去。
// mRequestQueue.add(0, request1, null);
// mRequestQueue.add(1, request2, null);
// mRequestQueue.add(2, request3, null);
}
示例8: HttpResponseListener
import com.yanzhenjie.nohttp.rest.Request; //导入依赖的package包/类
/**
* @param activity context用来实例化dialog.
* @param request 请求对象.
* @param httpCallback 回调对象.
* @param canCancel 是否允许用户取消请求.
* @param isLoading 是否显示dialog.
*/
public HttpResponseListener(Activity activity, Request<?> request, HttpListener<T> httpCallback, boolean canCancel, boolean isLoading) {
this.mActivity = activity;
this.mRequest = request;
if (activity != null && isLoading) {
mWaitDialog = new WaitDialog(activity);
mWaitDialog.setCancelable(canCancel);
mWaitDialog.setOnCancelListener(new DialogInterface.OnCancelListener() {
@Override
public void onCancel(DialogInterface dialog) {
mRequest.cancel();
}
});
}
this.callback = httpCallback;
}
示例9: sendPost
import com.yanzhenjie.nohttp.rest.Request; //导入依赖的package包/类
/**
* 向指定 URL 发送POST方法的请求
*
* @param url 发送请求的 URL
* @param params 请求的参数集合
* @return 远程资源的响应结果
*/
private static String sendPost(String url, Map<String, String> params) {
Request<String> request = NoHttp.createStringRequest(url, RequestMethod.POST);
request.setUserAgent("Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1;SV1)");
request.setContentType("application/x-www-form-urlencoded");
request.add(params);
// 调用同步请求,直接拿到请求结果。
Response<String> response = NoHttp.startRequestSync(request);
if (response.isSucceed()) {
return response.get();
} else {
return "";
}
}
示例10: sendRequest
import com.yanzhenjie.nohttp.rest.Request; //导入依赖的package包/类
/**
* 发送请求,获取json字符串
*/
public void sendRequest() {
requestQueue.cancelAll(); // 取消队列中的所有请求
Request<String> request = NoHttp.createStringRequest(REQUEST_URL);
request.setConnectTimeout(20000);
request.setReadTimeout(20000);
request.setContentType("application/json; charset=UTF-8");
request.setUserAgent("Mozilla/5.0 (Windows NT 10.0; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/50.0.2661.102 Safari/537.36");
requestQueue.add(REQUEST_WHAT, request, this);
}
示例11: doInBackground
import com.yanzhenjie.nohttp.rest.Request; //导入依赖的package包/类
@Override
protected RecentPost doInBackground(Void... params) {
String jsonStr = "";
Request<String> request = NoHttp.createStringRequest(PATH, RequestMethod.GET);
// 调用同步请求,直接拿到请求结果。
Response<String> response = NoHttp.startRequestSync(request);
if (response.isSucceed()) {
jsonStr = response.get();
}
try {
if (!"".equals(jsonStr)) {
JSONObject json = new JSONObject(jsonStr);
int id = json.getInt("id");
// 每条信息只推送一遍
if (id > AccountApp.pushID) {
String title = json.getString("title");
String date = json.getString("date");
String content = json.getString("content");
String url = json.getString("url");
return new RecentPost(title, date, content, url, id);
}
}
} catch (Exception e) {
e.printStackTrace();
}
return null;
}
示例12: getConnInfoHtml
import com.yanzhenjie.nohttp.rest.Request; //导入依赖的package包/类
/**
* 得到连接用户的信息 例如: <br />
* 45223109,12623,45.00,,0,58.154.209.141 <br />
* 45278986,13189,45.00,,0,58.154.209.141 <br />
* 流量,时长,余额,,0,IP地址
*
* @return
*/
private static String getConnInfoHtml() {
// 创建请求
Request<String> request = NoHttp.createStringRequest(IPGWUrl.POST_DETAILS, RequestMethod.POST);
request.add("action", "get_online_info")
.add("key", IPGWUrl.KEY);
// 调用同步请求,直接拿到请求结果。
Response<String> response = NoHttp.startRequestSync(request);
if (response.isSucceed()) {
return response.get();
} else {
return "";
}
}
示例13: onClick
import com.yanzhenjie.nohttp.rest.Request; //导入依赖的package包/类
@Override
public void onClick(View v) {
showDialog();
new Thread() {
public void run() {
// 在子线程中可以使用同步请求
Request<String> request = NoHttp.createStringRequest(Constants.URL_NOHTTP_JSONOBJECT,
RequestMethod.GET);
request.add("name", "yanzhenjie");
request.add("pwd", 123);
Response<String> response = NoHttp.startRequestSync(request);
handler.obtainMessage(0, response).sendToTarget();
}
}.start();
}
示例14: pushBody
import com.yanzhenjie.nohttp.rest.Request; //导入依赖的package包/类
/**
* 提交JSON、XML、String、InputStream、ByteArray。
*/
private void pushBody() {
/**
* 这里要注意的是:
* 1. 请求方法一定是POST、PUT等可以直接写流出去的方法。
*/
Request<String> request = NoHttp.createStringRequest(Constants.URL_NOHTTP_POSTBODY, RequestMethod.POST);
request.add("name", "yanzhenjie");
request.add("pwd", 123);
/**
* 下面就是怎么setBody,几种方法,根据自己的需要选择:
*/
// 1. 这里可以push任何数据上去(比如String、Json、XML、图片)。
// request.setDefineRequestBody(InputStream body, String contentType);
// 2. 这里可以push任何string数据(json、xml等),并可以指定contentType。
// request.setDefineRequestBody(String body, String contentType);
// 3. 下面的两个的contentType默认为application/json,传进去的数据要为json。
// request.setDefineRequestBodyForJson(JSONObject jsonBody);
// request.setDefineRequestBodyForJson(String jsonBody);
// 4. 这里的contentType默认为application/xml。
// request.setDefineRequestBodyForXML(String xmlBody);
// 这里我们用json多例子
String jsonBody = mEdtPostBody.getText().toString();
if (TextUtils.isEmpty(jsonBody)) {
Snackbar.show(this, R.string.request_json_body_input_tip);
} else {
Logger.i("提交的数据:" + jsonBody);
request.setDefineRequestBodyForJson(jsonBody);
request(0, request, httpListener, false, true);
}
}
示例15: onClick
import com.yanzhenjie.nohttp.rest.Request; //导入依赖的package包/类
@Override
public void onClick(View v) {
// 创建请求对象。
Request<String> request = NoHttp.createStringRequest(Constants.URL_NOHTTP_JSONOBJECT, RequestMethod.GET);
// 添加请求参数。
request.add("name", "yanzhenjie") // String型。
.add("pwd", 123) // int型。
.add("userAge", 1.25) // double型。
.add("nooxxx", 1.2F) // flocat型。
// 单个请求的超时时间,不指定就会使用全局配置。
.setConnectTimeout(10 * 1000) // 设置连接超时。
.setReadTimeout(20 * 1000) // 设置读取超时时间,也就是服务器的响应超时。
// 请求头,是否要添加头,添加什么头,要看开发者服务器端的要求。
.addHeader("Author", "sample")
.setHeader("User", "Jason")
// 设置一个tag, 在请求完(失败/成功)时原封不动返回; 多数情况下不需要。
.setTag(new Object())
// 设置取消标志。
.setCancelSign(this);
/*
* what: 当多个请求同时使用同一个OnResponseListener时用来区分请求, 类似handler的what一样。
* handle: 请求对象。
* onResponseListener 回调对象,接受请求结果。
*/
mQueue.add(NOHTTP_WHAT_TEST, request, onResponseListener);
}