下面列出了org.openqa.selenium.remote.http.HttpMethod#GET 实例代码,或者点击链接到github查看源代码,也可以在右侧发表评论。
@Override
public HttpRequest encode(Command command) {
String name = aliases.getOrDefault(command.getName(), command.getName());
CommandSpec spec = nameToSpec.get(name);
if (spec == null) {
throw new UnsupportedCommandException(command.getName());
}
Map<String, ?> parameters = amendParameters(command.getName(), command.getParameters());
String uri = buildUri(name, command.getSessionId(), parameters, spec);
HttpRequest request = new HttpRequest(spec.method, uri);
if (HttpMethod.POST == spec.method) {
String content = json.toJson(parameters);
byte[] data = content.getBytes(UTF_8);
request.setHeader(CONTENT_LENGTH, String.valueOf(data.length));
request.setHeader(CONTENT_TYPE, JSON_UTF_8.toString());
request.setContent(bytes(data));
}
if (HttpMethod.GET == spec.method) {
request.setHeader(CACHE_CONTROL, "no-cache");
}
return request;
}
@Test
public void shouldForwardRequestsToEndPoint() {
HttpHandler handler = new ReverseProxyHandler(tracer, factory.createClient(server.url));
HttpRequest req = new HttpRequest(HttpMethod.GET, "/ok");
req.addHeader("X-Cheese", "Cake");
handler.execute(req);
// HTTP headers are case insensitive. This is how the HttpUrlConnection likes to encode things
assertEquals("Cake", server.lastRequest.getHeader("x-cheese"));
}
protected static CommandSpec get(String path) {
return new CommandSpec(HttpMethod.GET, path);
}
/**
* This methods forms GET commands.
*
* @param url is the command URL
* @return an instance of {@link org.openqa.selenium.remote.CommandInfo}
*/
public static AppiumCommandInfo getC(String url) {
return new AppiumCommandInfo(url, HttpMethod.GET);
}