google-http-client

How to set the application name using the HTTP Client Library for Java?

好久不见. 提交于 2019-12-13 04:36:59
问题 I am using the HTTP Client Library for Java to access the Google Custom Search API and perform a search. String key = "..."; String cx = "..."; String query = "..."; // Set up the HTTP transport and JSON factory HttpTransport httpTransport = new NetHttpTransport(); JsonFactory jsonFactory = new JacksonFactory(); Customsearch customsearch = new Customsearch(httpTransport, jsonFactory,null); List<Result> resultList = null; try { Customsearch.Cse.List list = customsearch.cse().list(query); list

Using GoogleHttpClient to send multipart/form-data

妖精的绣舞 提交于 2019-12-12 03:55:37
问题 I am using the google-http-client for java to handle http connections on Android. Everything is HunkyDori with it thus far until trying to send a multipart/form-data Content. I am a little bit stuck, I am thinking about adapting the MultipartContent class to create my own version of MultipartFormContent . I need a version of MultipartEntity which would effectivly work like: HttpClient httpclient = new DefaultHttpClient(); HttpPost httppost = new HttpPost(url); FileBody bin = new FileBody(new

Set HTTP header in Drive request

蹲街弑〆低调 提交于 2019-12-11 12:27:48
问题 I want to detect conflict when updating a file to Drive. To accomplish this, it seems I have to set the If-Match header. Currently, I update the doc to Google Drive with this one-liner: mDriveFile = mService.files().update(mDriveFile.getId(), mDriveFile, byteContent).execute(); What is the simplest way to add the If-Match header in the request? Example in Files: update documentation does not tell how to set HTTP headers. 回答1: You can get the headers from Update object, add your own and put

How do I deserialize a json String to Java Object in App Engine

江枫思渺然 提交于 2019-12-11 02:03:57
问题 I have a UI which sends this object - com.google.api.services.compute.model.Network in JSON format as part of a HTTP request. I need to deserialize this object to the Java object. How do I do that? I wrote a simple POJO like below to mimic the behaviour. package com.techm.studio.client; import java.io.IOException; import com.google.api.services.compute.model.Network; import com.google.api.services.compute.model.NetworkRoutingConfig; import com.google.gson.Gson; import com.google.gson

Jersey client async POST request to not wait for response

断了今生、忘了曾经 提交于 2019-12-07 10:39:13
问题 I have created a simple Jersey client and it is able to successfully do a POST request with a payload. But right now it waits for a response from the http endpoint: public void callEndpoint(String endpoint, String payload) { try { ClientConfig config = new DefaultClientConfig(); Client client = Client.create(config); WebResource webResource = client.resource(getBaseURI(endpoint)); log.debug("Sending payload [" + payload + "] to URL - [" + getBaseURI(endpoint) + "]"); // POST method - Is this

Using proxies with Google HTTP Client Library for Java

怎甘沉沦 提交于 2019-12-06 05:38:16
问题 I use Google HTTP Client Library for Java to make simple JSON requests and parse responses. It works well when I don't go through a proxy. But now I'd like to allow my users to use a proxy (with authentication) functionality in my application. I looked in the HttpTransport, HttpRequestFactory and HttpRequestInitializer classes without any success. I've only slightly modified the examples so far (and mostly it was removing unnecessary code). So where in the code do I add the proxy settings?

Multipart Request to Box API via Google HTTP Client

為{幸葍}努か 提交于 2019-12-06 04:28:26
问题 I'm trying to call this specific method http://developers.box.com/docs/#files-upload-a-file in Box API with the help of Google HTTP Client library v1.14.1. Currently I see no way of doing this. If I was using http://hc.apache.org/httpclient-3.x/methods/multipartpost.html, I would add 2 items of StringPart and 1 item of FilePart. In Google HTTP Client library I see only MultipartContent and Part classes that do not seem to be able to handle pure name/value pairs, as StringPart referenced above

Using proxies with Google HTTP Client Library for Java

こ雲淡風輕ζ 提交于 2019-12-04 11:08:15
I use Google HTTP Client Library for Java to make simple JSON requests and parse responses. It works well when I don't go through a proxy. But now I'd like to allow my users to use a proxy (with authentication) functionality in my application. I looked in the HttpTransport, HttpRequestFactory and HttpRequestInitializer classes without any success. I've only slightly modified the examples so far (and mostly it was removing unnecessary code). So where in the code do I add the proxy settings? static final HttpTransport HTTP_TRANSPORT = new NetHttpTransport(); static final JsonFactory JSON_FACTORY