本文整理匯總了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));
}
}