httpParameters.setBooleanParameter("http.protocol.expect-continue", false); HttpPost request = new HttpPost("http://www.server.com/some_script.php?sid=" + String.valueOf(Math.random())); request.getParams().setParameter("http.socket.timeout", new Integer(5000));
HttpClientParams.setRedirecting(method.getParams(), false);
HttpPost postURL = new HttpPost(resourceURL); ... HttpClientParams.setRedirecting(postURL.getParams(), false);
HttpPost httppost = new HttpPost("myscript.php"); httppost.getParams().setBooleanParameter(CoreProtocolPNames.USE_EXPECT_CONTINUE, false);
HttpPost httpPostRequest = new HttpPost(URL); httpPostRequest.getParams().setParameter("http.socket.timeout", new Integer(600000));
private void sendRequest(StringEntity entity) throws ClientProtocolException, IOException, HttpBadResponseException { HttpPost method = new HttpPost(url); method.getParams().setParameter( CoreConnectionPNames.SO_TIMEOUT, socketTimeout * 1000); method.getParams().setParameter (CoreConnectionPNames.CONNECTION_TIMEOUT, connectionTimeout * 1000); method.setEntity(entity); httpResponse = httpClient.execute(method); checkResponse(httpResponse); }
private void sendRequest(StringEntity entity) throws ClientProtocolException, IOException, HttpBadResponseException { HttpPost method = new HttpPost(url); method.getParams().setParameter( CoreConnectionPNames.SO_TIMEOUT, socketTimeout * 1000); method.getParams().setParameter (CoreConnectionPNames.CONNECTION_TIMEOUT, connectionTimeout * 1000); method.setEntity(entity); httpResponse = httpClient.execute(method); checkResponse(httpResponse); }
// Set connection timeout int timeoutConnection = 3000; HttpConnectionParams.setConnectionTimeout(httppost.getParams(), timeoutConnection); // set socket timeout int timeoutSocket = 3000; HttpConnectionParams.setSoTimeout(httppost.getParams(), timeoutSocket); // Create the client HttpClient httpclient = new DefaultHttpClient(); url=urls[0].getUrl(); // Create the post HttpPost httppost = new HttpPost(urls[0].getUrl()); httppost.setEntity(new UrlEncodedFormEntity(urls[0].getParameters())); // Execute HTTP Post Request and get response HttpResponse responsePOST = httpclient.execute(httppost); resEntity = responsePOST.getEntity(); response=EntityUtils.toString(resEntity);
private void sendCancelRequest(String slaveEndpoint, String slaveJobId) { final HttpPost request = new HttpPost(slaveEndpoint); request.getParams().setParameter(HTTP_PARAM_SLAVE_JOB_ID, slaveJobId); request.getParams().setParameter(HTTP_PARAM_ACTION, ACTION_CANCEL); try { final HttpResponse response = _httpClient.execute(request); // handle the response final StatusLine statusLine = response.getStatusLine(); if (statusLine.getStatusCode() != 200) { throw new IllegalStateException("Slave server '" + slaveEndpoint + "' responded with an error to 'cancel' request: " + statusLine.getReasonPhrase() + " (" + statusLine.getStatusCode() + ")"); } } catch (Exception e) { if (e instanceof RuntimeException) { throw (RuntimeException) e; } throw new IllegalStateException("Failed to fire cancel request to slave server '" + slaveEndpoint + "' for job id '" + slaveJobId + "'", e); } }
public String SendHttpPost(String URL, JSONObject jsonObjSend) throws ClientProtocolException, IOException { DefaultHttpClient httpclient = new DefaultHttpClient(); HttpPost httpPostRequest = new HttpPost(URL); jsonObjSend.length(); List<NameValuePair> nameValuePairs = new ArrayList<NameValuePair>(jsonObjSend.length()); nameValuePairs.add(new BasicNameValuePair("data", jsonObjSend.toString())); UrlEncodedFormEntity en=new UrlEncodedFormEntity(nameValuePairs); en.getContent(); httpPostRequest.getParams().setParameter("http.socket.timeout", new Integer(600000)); httpPostRequest.setEntity(en); long t = System.currentTimeMillis(); HttpResponse response = (HttpResponse) httpclient.execute(httpPostRequest); responses = convertEntityToString(response.getEntity(), "UTF-8"); return responses; }
HttpPost post = new HttpPost(url); HttpClient hc = new DefaultHttpClient(); List<NameValuePair> nameValuePairs = new ArrayList<NameValuePair>(5); nameValuePairs.add(new BasicNameValuePair("name", name)); nameValuePairs.add(new BasicNameValuePair("email", email)); nameValuePairs.add(new BasicNameValuePair("mobile", mobile)); nameValuePairs.add(new BasicNameValuePair("subject", subject)); nameValuePairs.add(new BasicNameValuePair("message", message)); try { post.setEntity(new UrlEncodedFormEntity(nameValuePairs)); post.getParams().setBooleanParameter("http.protocol.expect-continue", false); HttpResponse rp = hc.execute(post); } catch (Exception e) { // TODO Auto-generated catch block e.printStackTrace(); } }
mHttpClient = new DefaultHttpClient(); mCredentials = new UsernamePasswordCredentials("username", "password"); mHttpClient.getCredentialsProvider().setCredentials( new AuthScope("twitter.com", 80, "Twitter API"), mCredentials); HttpPost post = new HttpPost("http://twitter.com/statuses/update.xml"); HttpParams params = post.getParams(); HttpClientParams.setCookiePolicy(params, CookiePolicy.BROWSER_COMPATIBILITY); HttpProtocolParams.setUseExpectContinue(params, false); post.setParams(params); ArrayList<NameValuePair> form = new ArrayList<NameValuePair>(); form.add(new BasicNameValuePair("status", "I'm tweeting!")); UrlEncodedFormEntity ent = new UrlEncodedFormEntity(form); post.setEntity(ent); HttpResponse resp = mHttpClient.execute(post);
HttpClient httpclient = new DefaultHttpClient(); uriString = "https://api.twitter.com/oauth2/token"; HttpPost httppost = new HttpPost(uriString); HttpParams httpParams = httppost.getParams(); HttpConnectionParams.setConnectionTimeout(httpParams, 10000); HttpConnectionParams.setSoTimeout(httpParams, 15000); String base64EncodedString =null; try { String encodedConsumerKey = URLEncoder.encode("twitter_consumer_key","UTF-8"); String encodedConsumerSecret = URLEncoder.encode("twitter_consumer_secret","UTF-8"); String authString = encodedConsumerKey +":"+encodedConsumerSecret; base64EncodedString = Base64.encodeToString(authString.getBytes("UTF-8"), Base64.NO_WRAP); //Changed here!!! } catch (Exception ex) { //do nothing for now... } httppost.setHeader(AUTHORIZATION, "Basic " + base64EncodedString); httppost.setHeader("Content-Type", "application/x-www-form-urlencoded;charset=UTF-8"); HttpResponse response =null; List<NameValuePair> nameValuePairs = new ArrayList<NameValuePair>(); nameValuePairs.add(new BasicNameValuePair("grant_type", "client_credentials")); httppost.setEntity(new UrlEncodedFormEntity(nameValuePairs,"UTF-8")); response = httpclient.execute(httppost); statusCode = response.getStatusLine().getStatusCode();
HttpClient client = new DefaultHttpClient(httpParameters); client.getParams().setParameter("http.protocol.version", HttpVersion.HTTP_1_1); client.getParams().setParameter("http.socket.timeout", 2000); client.getParams().setParameter("http.protocol.content-charset", HTTP.UTF_8); httpParameters.setBooleanParameter("http.protocol.expect-continue", false); HttpPost request = new HttpPost("http://xxxxxx.com/upload.php"); request.getParams().setParameter("http.socket.timeout", 5000); List<NameValuePair> postParameters = new ArrayList<NameValuePair>(); postParameters.add(new BasicNameValuePair("RPM",data)); try { UrlEncodedFormEntity formEntity = new UrlEncodedFormEntity(postParameters, HTTP.UTF_8); request.setEntity(formEntity); HttpResponse response = client.execute(request); //do with response
HttpPost httppost = new HttpPost(urlToSendCheckListReport); JSONObject json = new JSONObject(); // prepare JSON data: json.put("tag_id", tagID); json.put("building_id", buildingID); json.put("timestamp", new SimpleDateFormat("dd-MM-yyyy, HH:mm:ss").format(Calendar.getInstance().getTime())); JSONArray postjson=new JSONArray(); postjson.put(json); StringEntity entity = null; try { entity = new StringEntity(entityString); entity.setContentType("application/json"); } catch (UnsupportedEncodingException e) { e.printStackTrace(); } httppost.setEntity(entity); // Post the data: httppost.setHeader("json", json.toString()); httppost.getParams().setParameter("jsonpost",postjson); HttpResponse response = new DefaultHttpClient().execute(httppost); if(response != null) { .....Read the response }
HttpParams httpParameters = new BasicHttpParams(); HttpClient client = new DefaultHttpClient(httpParameters); client.getParams().setParameter("http.protocol.version", HttpVersion.HTTP_1_1); client.getParams().setParameter("http.socket.timeout", 2000); client.getParams().setParameter("http.protocol.content-charset", HTTP.UTF_8); httpParameters.setBooleanParameter("http.protocol.expect-continue", false); HttpPost request = new HttpPost(url); request.getParams().setParameter("http.socket.timeout", 5000); List<NameValuePair> postParameters = new ArrayList<NameValuePair>(); postParameters.add(new BasicNameValuePair("prm1", prm1value)); try { UrlEncodedFormEntity formEntity = new UrlEncodedFormEntity(postParameters, HTTP.UTF_8); request.setEntity(formEntity); HttpResponse response = client.execute(request); ... ..
DefaultHttpClient httpclient = new DefaultHttpClient(); httpclient.getAuthSchemes().register("ntlm", new NTLMSchemeFactory()); NTCredentials creds = new NTCredentials("user_name", "password", "", "http://www.musowls.org/"); httpclient.getCredentialsProvider().setCredentials(AuthScope.ANY, creds); HttpConnectionParams.setConnectionTimeout(httpclient.getParams(), 5000); HttpPost httppost = new HttpPost("http://www.musowls.org/assignments/assignmentsbystudentxml.aspx"); httppost.getParams().setBooleanParameter(CoreProtocolPNames.USE_EXPECT_CONTINUE, false); HttpResponse response = httpclient.execute(httppost); // ERROR HAPPENS HERE responseXML = EntityUtils.toString(response.getEntity()); Log.d("Responce", responseXML);
HttpPost post = new HttpPost(); post.getAllHeaders(); post.getMethod(); // Post or get request post.getParams(); // Returns params post.getURI(); // Current Uri called
public HttpResponse deployPomWithRest(final String repositoryId, final File pomFile) throws IOException { // the method we are calling final HttpPost filePost = new HttpPost(nexusRestClient.toNexusURL("service/local/artifact/maven/content").toExternalForm()); filePost.getParams().setBooleanParameter(CoreProtocolPNames.USE_EXPECT_CONTINUE, true); final MultipartEntity multipartEntity = new MultipartEntity(); multipartEntity.addPart("r", new StringBody(repositoryId)); multipartEntity.addPart("hasPom", new StringBody(Boolean.TRUE.toString())); multipartEntity.addPart(pomFile.getName(), new FileBody(pomFile)); filePost.setEntity(multipartEntity); LOG.debug("URL: " + filePost.getURI()); LOG.debug("Method: Post"); LOG.debug("params: "); LOG.debug("\tr: " + repositoryId); LOG.debug("\thasPom: true"); LOG.debug("\tpom: " + pomFile); return nexusRestClient.executeHTTPClientMethod(filePost); }
private void postOnFacebook() { try { HttpPost httpPost = new HttpPost("https://graph.facebook.com/me/photos"); MultipartEntity entity = new MultipartEntity(); String base64Image = "iVBORw0KGgoAAAANSUhEUgAAAAUAAAAFCAIAAAACDbGyAAAAAXNSR0IArs4c6QAAAARnQU1BAACxjwv8YQUAAAAJcEhZcwAADsMAAA7DAcdvqGQAAAASSURBVBhXY3gro4KMKOPLqAAAq/UdZuRmLacAAAAASUVORK5CYII="; byte[] imageData = Base64.decode(base64Image, 0); entity.addPart("access_token", new StringBody("your access token")); entity.addPart("message", new StringBody("test msg")); entity.addPart("source", new ByteArrayBody(imageData, "test")); CloseableHttpClient httpclient = HttpClientBuilder.create().build(); httpPost.getParams().setBooleanParameter(USE_EXPECT_CONTINUE, false); httpPost.setEntity(entity); HttpResponse resp = httpclient.execute(httpPost); HttpEntity entity2 = resp.getEntity(); if (entity != null) { String responseBody = EntityUtils.toString(entity2); responseBody.toString(); } } catch (Exception ex) { ex.printStackTrace(); } }