本文整理汇总了Java中com.github.kevinsawicki.http.HttpRequest.header方法的典型用法代码示例。如果您正苦于以下问题:Java HttpRequest.header方法的具体用法?Java HttpRequest.header怎么用?Java HttpRequest.header使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类com.github.kevinsawicki.http.HttpRequest
的用法示例。
在下文中一共展示了HttpRequest.header方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: uploadMeasurements
import com.github.kevinsawicki.http.HttpRequest; //导入方法依赖的package包/类
@Override
public RequestResult uploadMeasurements(String content) {
Log.d("uploadMeasurements(): Sending post request");
try {
HttpRequest request = HttpRequest.post(uploadUrl)
.followRedirects(false)
.connectTimeout(CONN_TIMEOUT)
.readTimeout(READ_TIMEOUT);
// add json as request content
request.header("Content-Type", "application/json");
request.send(content);
return handleResponse(request.code(), request.body());
} catch (HttpRequestException ex) {
Log.d("uploadMeasurements(): Errors encountered", ex);
reportExceptionWithSuppress(ex);
return RequestResult.Failure;
}
}
示例2: addCredentialsTo
import com.github.kevinsawicki.http.HttpRequest; //导入方法依赖的package包/类
private HttpRequest addCredentialsTo(HttpRequest request) {
// Required params for
request.header(HEADER_PARSE_REST_API_KEY, PARSE_REST_API_KEY);
request.header(HEADER_PARSE_APP_ID, PARSE_APP_ID);
/**
* NOTE: This may be where you want to add a header for the api token that was saved when you
* logged in. In the bootstrap sample this is where we are saving the session id as the token.
* If you actually had received a token you'd take the "apiKey" (aka: token) and add it to the
* header or form values before you make your requests.
*/
/**
* Add the user name and password to the request here if your service needs username or password for each
* request. You can do this like this:
* request.basic("myusername", "mypassword");
*/
return request;
}
示例3: prepareHttpRequest
import com.github.kevinsawicki.http.HttpRequest; //导入方法依赖的package包/类
public static HttpRequest prepareHttpRequest(final Request request) throws IOException {
// Extract details from incoming request from Retrofit
final String requestUrl = request.getUrl();
final String requestMethod = request.getMethod();
final List<Header> requestHeaders = request.getHeaders();
// URL and Method
final HttpRequest httpRequest = new HttpRequest(requestUrl, requestMethod);
// Headers
for (Header header: requestHeaders) {
httpRequest.header(header.getName(), header.getValue());
}
return httpRequest;
}
示例4: test02
import com.github.kevinsawicki.http.HttpRequest; //导入方法依赖的package包/类
@Test
public void test02() throws Exception {
//49
ObjectMapper mapper = new ObjectMapper();
List<String> ret = new ArrayList<>();
String url = "https://xueqiu.com/stock/cata/stocklist.json?page=";
String param = "&size=100&order=desc&orderby=percent&type=11%2C12&_=1461851096446";
for (int i = 1; i <= 50; i++) {
String dest = url + i + param;
HttpRequest req = HttpRequest.get(dest);
req.header("Cookie", "xq_a_token=93b9123bccf67168e3adb0c07d89b9e1f6cc8db6;");
String body = req.body();
ret.add(body);
JsonNode jsonNode = mapper.readTree(body);
JsonNode stocks = jsonNode.get("stocks");
stocks.forEach(st->{
Stock stock = null;
try {
stock = mapper.readValue(st.toString(), Stock.class);
DaoUtil.dao.insert(stock);
} catch (Exception e) {
e.printStackTrace();
}
});
Thread.sleep(500);
System.out.println("fetch url " + dest + " result " + body);
}
System.out.println("final result---> " + mapper.writeValueAsString(ret));
}
示例5: prepareApiRequest
import com.github.kevinsawicki.http.HttpRequest; //导入方法依赖的package包/类
/**
* Prepares an arbitrary API request by injecting an ID Token into an HttpRequest. Uses an
* external library to make my life easier, but you can modify this to use whatever in case you
* don't like the (small) dependency.
*/
public static HttpRequest prepareApiRequest(HttpRequest request, String idToken, String cookies)
throws IOException {
request = request.authorization("Bearer " + idToken).acceptJson();
request = request.header("Cookie", cookies);
return request;
}
示例6: setHeadersFromJsonObject
import com.github.kevinsawicki.http.HttpRequest; //导入方法依赖的package包/类
protected void setHeadersFromJsonObject(HttpRequest request, JSONObject headers) throws JSONException
{
Iterator<?> keys = headers.keys();
while(keys.hasNext()) {
String key = (String) keys.next();
request.header(key, (String) headers.get(key));
}
}