本文整理匯總了Java中com.google.api.client.http.GenericUrl.put方法的典型用法代碼示例。如果您正苦於以下問題:Java GenericUrl.put方法的具體用法?Java GenericUrl.put怎麽用?Java GenericUrl.put使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類com.google.api.client.http.GenericUrl
的用法示例。
在下文中一共展示了GenericUrl.put方法的9個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: initiateResumableUpload
import com.google.api.client.http.GenericUrl; //導入方法依賴的package包/類
/**
* Initiate a resumable upload direct to the cloud storage API. Providing an origin will enable
* CORS requests to the upload URL from the specified origin.
*
* @param bucket the cloud storage bucket to upload to
* @param name the name of the resource that will be uploaded
* @param contentType the resource's content/mime type
* @param origin the origin to allow for CORS requests
* @return the upload URL
* @see <a href="https://cloud.google.com/storage/docs/json_api/v1/how-tos/resumable-upload">Performing a Resumable Upload</a>
*/
public String initiateResumableUpload(String bucket, String name, String contentType, String origin) {
String uploadUrl = String.format("%s/upload/storage/v1/b/%s/o", BASE_GOOGLE_API_URL, bucket);
GenericUrl url = new GenericUrl(uploadUrl);
url.put("uploadType", "resumable");
url.put("name", name);
HttpHeaders headers = new HttpHeaders();
headers.put("X-Upload-Content-Type", contentType);
if (origin != null) {
headers.put("Origin", origin); // Add origin header for CORS support
}
HttpResponse response;
try {
response = httpRequestFactory
.buildPostRequest(url, null)
.setHeaders(headers)
.execute();
} catch (IOException e) {
throw new GoogleCloudStorageException(e, "Cannot initiate upload: %s", e.getMessage());
}
return response.getHeaders().getLocation();
}
示例2: buildHttpResponse
import com.google.api.client.http.GenericUrl; //導入方法依賴的package包/類
/**
* Builds a HttpResponse with the given string response.
*
* @param header header value to provide or null if none.
* @param uploadId upload id to provide in the url upload id param or null if none.
* @param uploadType upload type to provide in url upload type param or null if none.
* @return HttpResponse with the given parameters
* @throws IOException
*/
private HttpResponse buildHttpResponse(String header, String uploadId, String uploadType)
throws IOException {
MockHttpTransport.Builder builder = new MockHttpTransport.Builder();
MockLowLevelHttpResponse resp = new MockLowLevelHttpResponse();
builder.setLowLevelHttpResponse(resp);
resp.setStatusCode(200);
GenericUrl url = new GenericUrl(HttpTesting.SIMPLE_URL);
if (header != null) {
resp.addHeader("X-GUploader-UploadID", header);
}
if (uploadId != null) {
url.put("upload_id", uploadId);
}
if (uploadType != null) {
url.put("uploadType", uploadType);
}
return builder.build().createRequestFactory().buildGetRequest(url).execute();
}
示例3: testResponseLogs
import com.google.api.client.http.GenericUrl; //導入方法依賴的package包/類
/**
* Check that a response logs with the correct log.
*/
@Test
public void testResponseLogs() throws IOException {
new UploadIdResponseInterceptor().interceptResponse(buildHttpResponse("abc", null, "type"));
GenericUrl url = new GenericUrl(HttpTesting.SIMPLE_URL);
url.put("uploadType", "type");
String worker = System.getProperty("worker_id");
expectedLogs.verifyDebug("Upload ID for url " + url + " on worker " + worker + " is abc");
}
示例4: prepareUrl
import com.google.api.client.http.GenericUrl; //導入方法依賴的package包/類
@Override
protected void prepareUrl(GenericUrl url, Class<?> parseAsType) {
super.prepareUrl(url, parseAsType);
if (partialResponse && parseAsType != null) {
url.put("fields", GoogleAtom.getFieldsFor(parseAsType));
}
}
示例5: delete
import com.google.api.client.http.GenericUrl; //導入方法依賴的package包/類
/**
* Send a DELETE request. Deletes a resource.
*
* @param <T>
* @param requestUrl
* @param responseType
* @param filter
* @return deleted object.
* @throws IOException
*/
public <U, T extends ResponseEnvelope<U>> U delete(final GenericUrl requestUrl, final Class<T> responseType, final Filter filter) throws IOException {
if (filter != null) {
Map<String, String> queryParams = filter.getQueryParams();
for (Entry<String, String> queryParam : queryParams.entrySet()) {
requestUrl.put(queryParam.getKey(), queryParam.getValue());
}
}
HttpRequest httpRequest = requestFactory.buildDeleteRequest(requestUrl);
return execute(httpRequest, responseType);
}
示例6: wolfReq
import com.google.api.client.http.GenericUrl; //導入方法依賴的package包/類
public void wolfReq(String s)throws Exception
{
String appid="JHG2AQ-KEUPARWGKH";
HttpTransport httpTransport = new NetHttpTransport();
HttpRequestFactory requestFactory =
httpTransport.createRequestFactory();
GenericUrl url1 = new
GenericUrl("http://api.wolframalpha.com/v2/query");
url1.put("input",s);
url1.put("output","JSON");
url1.put("appid",appid);
final HttpRequest request = requestFactory.buildGetRequest(url1);
new AsyncTask<Void, Void, String>() {
@Override
protected String doInBackground(Void... params) {
HttpResponse httpResponse;
try {
httpResponse = request.execute();
InputStream inputStream = httpResponse.getContent();
int ch;
String result = "";
while ((ch = inputStream.read()) != -1) {
result+=(char)ch;
}
httpResponse.disconnect();
JSONObject data = new JSONObject(result);
result = data.getJSONObject("queryresult").getJSONArray("pods").getJSONObject(1).getJSONArray("subpods").getJSONObject(0).getJSONObject("img").getString ("src");
URL urlConnection = new URL(result);
HttpURLConnection connection =
(HttpURLConnection) urlConnection
.openConnection();
connection.setDoInput(true);
connection.setConnectTimeout(20000);
connection.connect();
InputStream input =
connection.getInputStream();
Bitmap myBitmap =
BitmapFactory.decodeStream(input);
bmp=myBitmap;
connection.disconnect();
Log.d("result",bmp.toString());
final Message message2 = new Message.Builder()
.setUser(you)
.setRightMessage(false)
.setPicture(myBitmap)
.hideIcon(true)
.setType(Message.Type.PICTURE)
.build();
//Set to chat view
runOnUiThread(new Runnable() {
@Override
public void run() {
chatView.send(message2);
}
});
} catch (Exception e) {
e.printStackTrace();
}
return null;
}
}.execute();
}
示例7: wolfReq
import com.google.api.client.http.GenericUrl; //導入方法依賴的package包/類
public static void wolfReq(String s)throws Exception
{
String appid="JHG2AQ-KEUPARWGKH";
HttpTransport httpTransport = new NetHttpTransport();
HttpRequestFactory requestFactory =
httpTransport.createRequestFactory();
GenericUrl url1 = new
GenericUrl("http://api.wolframalpha.com/v2/query");
url1.put("input",s);
url1.put("output","JSON");
url1.put("appid",appid);
final HttpRequest request = requestFactory.buildGetRequest(url1);
String resultPassed = "";
new AsyncTask<Void, Void, String>() {
@Override
protected String doInBackground(Void... params) {
HttpResponse httpResponse = null;
try {
httpResponse = request.execute();
InputStream inputStream = httpResponse.getContent();
int ch;
String result = "";
while ((ch = inputStream.read()) != -1) {
result+=(char)ch;
}
httpResponse.disconnect();
JSONObject data = new JSONObject(result);
result = data.getJSONObject("queryresult").getJSONArray("pods").getJSONObject(1).getJSONArray("subpods").getJSONObject(0).getString("plaintext");
Log.d("result",result);
setResult(result);
return result;
} catch (Exception e) {
e.printStackTrace();
}
return null;
}
}.execute();
}
示例8: getSignature
import com.google.api.client.http.GenericUrl; //導入方法依賴的package包/類
public LinkedHashMap<String, String> getSignature(Map<String, String> options, RequestMethod requestMethod, String endpoint) {
LinkedHashMap<String, String> map = new LinkedHashMap<String, String>();
OAuthParameters parameters = new OAuthParameters();
parameters.computeTimestamp();
parameters.computeNonce();
parameters.version = "1.0";
parameters.consumerKey = wooCommerce.getWc_key();
GenericUrl genericUrl = new GenericUrl();
genericUrl.setScheme(wooCommerce.isHttps() ? "https" : "http");
genericUrl.setHost(wooCommerce.getBaseUrl());
genericUrl.appendRawPath("/wc-api");
genericUrl.appendRawPath("/v3");
/*
* The endpoint to be called is specified next
* */
genericUrl.appendRawPath(endpoint);
for (Map.Entry<String, String> entry : options.entrySet())
{
System.out.println(entry.getKey() + "/" + entry.getValue());
genericUrl.appendRawPath("/"+entry.getValue());
}
OAuthHmacSigner oAuthHmacSigner = new OAuthHmacSigner();
oAuthHmacSigner.clientSharedSecret = wooCommerce.getWc_secret();
parameters.signer = oAuthHmacSigner;
parameters.signatureMethod = wooCommerce.getSigning_method().getVal();
try {
parameters.computeSignature(requestMethod.getVal(), genericUrl);
} catch (GeneralSecurityException e) {
e.printStackTrace();
}
map.put("oauth_consumer_key", parameters.consumerKey);
map.put("oauth_signature_method", parameters.signatureMethod);
map.put("oauth_timestamp", parameters.timestamp);
map.put("oauth_nonce", parameters.nonce);
map.put("oauth_version", parameters.version);
map.put("oauth_signature", parameters.signature);
genericUrl.put("oauth_consumer_key", parameters.consumerKey);
genericUrl.put("oauth_signature_method", parameters.signatureMethod);
genericUrl.put("oauth_timestamp", parameters.timestamp);
genericUrl.put("oauth_nonce", parameters.nonce);
genericUrl.put("oauth_version", parameters.version);
genericUrl.put("oauth_signature", parameters.signature);
Log.i(TAG,genericUrl.build());
return map;
}
示例9: get
import com.google.api.client.http.GenericUrl; //導入方法依賴的package包/類
/**
* Send a GET request. Retrieves either a collection of resources or a single resource.
*
* @param <U>
* @param <T>
* @param requestUrl
* @param responseType
* @param filter
* @return fetched object.
* @throws IOException
*/
public <U, T extends ResponseEnvelope<U>> U get(final GenericUrl requestUrl, final Class<T> responseType, final Filter filter) throws IOException {
if (filter != null) {
Map<String, String> queryParams = filter.getQueryParams();
for (Entry<String, String> queryParam : queryParams.entrySet()) {
requestUrl.put(queryParam.getKey(), queryParam.getValue());
}
}
HttpRequest httpRequest = requestFactory.buildGetRequest(requestUrl);
return execute(httpRequest, responseType);
}