本文整理汇总了Java中com.google.appengine.api.urlfetch.HTTPMethod.POST属性的典型用法代码示例。如果您正苦于以下问题:Java HTTPMethod.POST属性的具体用法?Java HTTPMethod.POST怎么用?Java HTTPMethod.POST使用的例子?那么, 这里精选的属性代码示例或许可以为您提供帮助。您也可以进一步了解该属性所在类com.google.appengine.api.urlfetch.HTTPMethod
的用法示例。
在下文中一共展示了HTTPMethod.POST属性的9个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: send
/**
* @return the response body as a String.
* @throws IOException for 500 or above or general connection problems.
* @throws InvalidStoreRequestException for any response code not 200.
*/
String send(String base) throws IOException {
URL url = new URL(base + urlBuilder.toString());
HTTPRequest req = new HTTPRequest(url, HTTPMethod.POST, getFetchOptions());
// TODO(ohler): use multipart/form-data for efficiency
req.setHeader(new HTTPHeader("Content-Type", "application/x-www-form-urlencoded"));
req.setHeader(new HTTPHeader(WALKAROUND_TRUSTED_HEADER, secret.getHexData()));
// NOTE(danilatos): Appengine will send 503 if the backend is at the
// max number of concurrent requests. We might come up with a use for
// handling this error code specifically. For now, we didn't go through
// the code to make sure that all other overload situations also manifest
// themselves as 503 rather than random exceptions that turn into 500s.
// Therefore, the code in this class treats all 5xx responses as an
// indication of possible overload.
req.setHeader(new HTTPHeader("X-AppEngine-FailFast", "true"));
req.setPayload(contentBuilder.toString().getBytes(Charsets.UTF_8));
log.info("Sending to " + url);
String ret = fetch(req);
log.info("Request completed");
return ret;
}
示例2: getRequestMethod
@Override
public String getRequestMethod() {
String outMethod = "unknown";
if (_requestMethod == HTTPMethod.GET) {
outMethod = "GET";
} else if (_requestMethod == HTTPMethod.PUT) {
outMethod = "PUT";
} else if (_requestMethod == HTTPMethod.POST) {
outMethod = "POST";
} else if (_requestMethod == HTTPMethod.HEAD) {
outMethod = "HEAD";
} else if (_requestMethod == HTTPMethod.DELETE) {
outMethod = "DELETE";
}
return outMethod;
}
示例3: trackEventToGoogleAnalytics
/**
* Posts an Event Tracking message to Google Analytics.
*
* @param category the required event category
* @param action the required event action
* @param label the optional event label
* @param value the optional value
* @return true if the call succeeded, otherwise false
* @exception IOException if the URL could not be posted to
*/
public int trackEventToGoogleAnalytics(
String category, String action, String label, String value) throws IOException {
Map<String, String> map = new LinkedHashMap<>();
map.put("v", "1"); // Version.
map.put("tid", gaTrackingId);
map.put("cid", gaClientId);
map.put("t", "event"); // Event hit type.
map.put("ec", encode(category, true));
map.put("ea", encode(action, true));
map.put("el", encode(label, false));
map.put("ev", encode(value, false));
HTTPRequest request = new HTTPRequest(GA_URL_ENDPOINT, HTTPMethod.POST);
request.addHeader(CONTENT_TYPE_HEADER);
request.setPayload(getPostData(map));
HTTPResponse httpResponse = urlFetchService.fetch(request);
// Return True if the call was successful.
return httpResponse.getResponseCode();
}
开发者ID:GoogleCloudPlatform,项目名称:appengine-googleanalytics-java,代码行数:30,代码来源:GoogleAnalyticsTracking.java
示例4: getResponseProxyPOST
public static String getResponseProxyPOST(URL url) throws MalformedURLException, UnsupportedEncodingException, IOException {
URLFetchService fetcher = URLFetchServiceFactory.getURLFetchService();
String base64payload = "base64url=" + Base64UrlSafe.encodeServer(url.toString());
String urlStr = url.toString();
if (urlStr.contains("?")) {
base64payload = "base64url=" + Base64UrlSafe.encodeServer(urlStr.substring(0, urlStr.indexOf("?")));
base64payload += "&base64content=" + Base64UrlSafe.encodeServer(urlStr.substring(urlStr.indexOf("?") + 1));
} else {
base64payload = "base64url=" + Base64UrlSafe.encodeServer(urlStr);
}
HTTPRequest httpRequest = new HTTPRequest(new URL(HttpClientGAE.POSTPROXY_PHP), HTTPMethod.POST, FetchOptions.Builder.withDeadline(30d).doNotValidateCertificate());
httpRequest.setPayload(base64payload.getBytes(UTF8));
HTTPResponse response = fetcher.fetch(httpRequest);
String processResponse = HttpClientGAE.processResponse(response);
logger.info("proxying " + url + "\nprocessResponse:" + processResponse);
return processResponse;
}
示例5: fetch
private HttpResponse fetch(String url, HttpRequestOptions requestOptions,
HTTPMethod method, String content) throws IOException {
final FetchOptions options = getFetchOptions(requestOptions);
String currentUrl = url;
for (int i = 0; i <= requestOptions.getMaxRedirects(); i++) {
HTTPRequest httpRequest = new HTTPRequest(new URL(currentUrl),
method, options);
addHeaders(httpRequest, requestOptions);
if (method == HTTPMethod.POST && content != null) {
httpRequest.setPayload(content.getBytes());
}
HTTPResponse httpResponse;
try {
httpResponse = fetchService.fetch(httpRequest);
} catch (ResponseTooLargeException e) {
return new TooLargeResponse(currentUrl);
}
if (!isRedirect(httpResponse.getResponseCode())) {
boolean isResponseTooLarge =
(getContentLength(httpResponse) > requestOptions.getMaxBodySize());
return new AppEngineFetchResponse(httpResponse,
isResponseTooLarge, currentUrl);
} else {
currentUrl = getResponseHeader(httpResponse, "Location").getValue();
}
}
throw new IOException("exceeded maximum number of redirects");
}
示例6: setRequestMethod
@Override
public void setRequestMethod(final String method) throws ProtocolException {
// Pasar de lo que espera HttpURLConnection de java a lo que espera URLFetch
if (method.equals("GET")) {
_requestMethod = HTTPMethod.GET;
} else if (method.equals("PUT")) {
_requestMethod = HTTPMethod.PUT;
} else if (method.equals("POST")) {
_requestMethod = HTTPMethod.POST;
} else if (method.equals("HEAD")) {
_requestMethod = HTTPMethod.HEAD;
} else if (method.equals("DELETE")) {
_requestMethod = HTTPMethod.DELETE;
}
}
示例7: send
public void send(String from, String to, String body, String inReplyTo, String references) {
try {
HTTPRequest request = new HTTPRequest(new URL(SENDGRID_SEND_URL), HTTPMethod.POST);
request.addHeader(new HTTPHeader(CONTENT_TYPE, FORM_UTF8_MIME));
request.setPayload(encodeQuery(new ImmutableMap.Builder<String, String>()
.put("api_user", apiUser)
.put("api_key", apiKey)
.put("to", to)
.put("from", from)
.put("subject", "Automated testing service response")
.put("text", isNullOrEmpty(body) ? " " : body) // SendGrid rejects an empty body.
.put("headers", toJSONString(filterValues(
ImmutableMap.of(
"In-Reply-To", nullToEmpty(inReplyTo),
"References", nullToEmpty(references)),
not(equalTo("")))))
.build()).getBytes(UTF_8));
HTTPResponse response = getURLFetchService().fetch(request);
if (response.getResponseCode() != HttpServletResponse.SC_OK) {
logger.warning(String.format(
"%d: %s",
response.getResponseCode(),
new String(response.getContent(), UTF_8)));
}
metrics.addActivity("autoreply");
} catch (IOException e) {
throw new RuntimeException(e);
}
}
示例8: testPayload
@Test
public void testPayload() throws Exception {
URLFetchService service = URLFetchServiceFactory.getURLFetchService();
URL url = getFetchUrl();
HTTPRequest req = new HTTPRequest(url, HTTPMethod.POST);
req.setHeader(new HTTPHeader("Content-Type", "application/octet-stream"));
req.setPayload("Tralala".getBytes(UTF_8));
HTTPResponse response = service.fetch(req);
String content = new String(response.getContent());
Assert.assertEquals("Hopsasa", content);
}
示例9: checkURLs
/**
* Checks URLs using the Google Safe Browsing Lookup API
*
* @param ofy Objectify
* @param urls this URLs will be checked. At most 500 URLs can be processed
* at once.
* @return GET_RESP_BODY = “phishing” | “malware” | "unwanted" |
* “phishing,malware” | "phishing,unwanted" | "malware,unwanted" |
* "phishing,malware,unwanted" | ""
* @throws java.io.IOException there was a communication problem, the server
* is unavailable, over quota or something different.
*/
public static String[] checkURLs(Objectify ofy, String urls[]) throws
IOException {
String[] result = new String[urls.length];
Arrays.fill(result, "");
try {
URL u = new URL(
"https://sb-ssl.google.com/safebrowsing/api/lookup?client=npackdweb&key=" +
getSetting(ofy, "PublicAPIKey", "") +
"&appver=1&pver=3.1");
URLFetchService s = URLFetchServiceFactory.getURLFetchService();
StringBuilder sb = new StringBuilder();
sb.append(urls.length);
for (String url : urls) {
sb.append('\n').append(new URL(url).toExternalForm());
}
//LOG.info("Google Safe Browsing API call:" + sb.toString());
HTTPRequest ht = new HTTPRequest(u, HTTPMethod.POST);
ht.setPayload(sb.toString().getBytes("US-ASCII"));
HTTPResponse r = s.fetch(ht);
int rc = r.getResponseCode();
/*LOG.info("Google Safe Browsing API response code:" +
rc);*/
if (rc == 200) {
/*LOG.info("Google Safe Browsing API response:" +
new String(r.
getContent(), "US-ASCII"));*/
final BufferedReader br =
new BufferedReader(new StringReader(new String(r.
getContent(), "US-ASCII")));
int i = 0;
String line;
while ((i < result.length) && (line = br.readLine()) != null) {
if (line.equals("ok")) {
result[i] = "";
} else {
result[i] = line;
}
i++;
}
} else if (rc == 204) {
// OK
} else if (rc == 400) {
throw new IOException(new String(r.getContent()));
} else {
throw new IOException(
"Unknown exception from the Google Safe Browsing API");
}
} catch (MalformedURLException ex) {
throw new IOException(ex);
}
return result;
}