logger.log(Level.FINE, httpPost.toString()); logger.log(Level.FINE, xmlMessageString);
HttpPost request = new HttpPost("url"); List<NameValuePair> value=new ArrayList<NameValuePair>(); value.add(new BasicNameValuePair("name",string)); System.out.println("Json obj="+string); UrlEncodedFormEntity entity=new UrlEncodedFormEntity(value); request.setEntity(entity); client.execute(request); System.out.println("after sending :"+request.toString()); } catch(Exception e) {System.out.println("Exp="+e); } }
HttpPost post = new HttpPost("www.google.com"); post.setHeader(new BasicHeader("User-Agent", "random client")); HttpEntity entity = new StringEntity("yellaworld"); post.setEntity(entity); Header[] headers = post.getAllHeaders(); String content = EntityUtils.toString(entity); System.out.println(post.toString()); for (Header header : headers) { System.out.println(header.getName() + ": " + header.getValue()); } System.out.println(); System.out.println(content);
Try this,It may help u public void executeHttpPost(String string) throws Exception { //This method for HttpConnection try { HttpClient client = new DefaultHttpClient(); HttpPost request = new HttpPost("URL"); List<NameValuePair> value=new ArrayList<NameValuePair>(); value.add(new BasicNameValuePair("Name",string)); UrlEncodedFormEntity entity=new UrlEncodedFormEntity(value); request.setEntity(entity); client.execute(request); System.out.println("after sending :"+request.toString()); } catch(Exception e) {System.out.println("Exp="+e); } }
protected ObjectNode executePost(HttpPost httpPost) { Objects.requireNonNull(httpPost); ObjectNode result = null; CloseableHttpResponse response = null; String entityString; try { response = httpclient.execute(httpPost); HttpEntity entity = response.getEntity(); // TODO: handle retry if (response.getStatusLine() != null && response.getStatusLine().getStatusCode() >= HttpStatus.SC_OK && entity != null) { entityString = EntityUtils.toString(entity); result = mapper.readValue(entityString, ObjectNode.class); } } catch (IOException ex) { LOGGER.error("IO error:\n{}\n{}\n{}", httpPost.toString(), response, ex.getMessage()); } finally { try { if (response != null) { response.close(); } } catch (IOException ignored) { LOGGER.trace("IOException", ignored); } } return result; }
public SiteVerifyResponse verify(String gRecaptchaResponse, String remoteIp) throws IOException { HttpPost httpPost = new HttpPost(SITEVERIFY_URL); httpPost.addHeader("User-Agent", USER_AGENT); List<NameValuePair> parameters = new ArrayList<>(); parameters.add(new BasicNameValuePair("secret", this.secret)); parameters.add(new BasicNameValuePair("response", gRecaptchaResponse)); parameters.add(new BasicNameValuePair("remoteip", remoteIp)); httpPost.setEntity(new UrlEncodedFormEntity(parameters)); logger.debug(httpPost.toString()); logger.debug(parameters.toString()); HttpResponse httpResponse = httpClient.execute(httpPost); logger.debug(httpResponse.getStatusLine().toString()); String responseBody = new BufferedReader(new InputStreamReader(httpResponse.getEntity().getContent())) .lines() .parallel() .collect(Collectors.joining("\n")); logger.debug(responseBody); SiteVerifyResponse siteVerifyResponse = gson.fromJson(responseBody, SiteVerifyResponse.class); logger.debug(siteVerifyResponse.toString()); return siteVerifyResponse; }
httppost.setHeader(new BasicHeader("Authorization", "Basic "+encoded_login)); System.out.println("URL="+httppost.toString());
Log.d("msg", "httppost : "+httpPost.toString());
public HttpResponse post(String uri, String json, boolean signatureRequired) throws BitPayException { try { HttpPost post = new HttpPost(_baseUrl + uri); post.setEntity(new ByteArrayEntity(json.getBytes("UTF8"))); if (signatureRequired) { post.addHeader("x-signature", KeyUtils.sign(_ecKey, _baseUrl + uri + json)); post.addHeader("x-identity", KeyUtils.bytesToHex(_ecKey.getPubKey())); } post.addHeader("x-accept-version", BITPAY_API_VERSION); post.addHeader("x-bitpay-plugin-info", BITPAY_PLUGIN_INFO); post.addHeader("Content-Type", "application/json"); _log.info(post.toString()); return _httpClient.execute(post); } catch (UnsupportedEncodingException e) { throw new BitPayException("Error: POST failed\n" + e.getMessage()); } catch (ClientProtocolException e) { throw new BitPayException("Error: POST failed\n" + e.getMessage()); } catch (IOException e) { throw new BitPayException("Error: POST failed\n" + e.getMessage()); } }
client.execute(post, localContext); } catch (IOException e) { Log.e("Callable try", post.toString());
log.debug("httpPost is: " + httpPost.toString()); response = httpClient.execute(httpPost); String responseString = null;
@Override public Boolean handleResponse(HttpResponse response) throws IOException { try { if (200 != response.getStatusLine().getStatusCode()) { refreshAddressCache(); handleErrorResponse(response, httpPost); Registry r = Lookout.registry(); r.counter( r.createId(LOOKOUT_REPORT_FAIL_COUNT_ID).withTag(LOW_PRIORITY_TAG)) .inc(); return false; } else {//success logger.debug("<< report to lookout gateway ok.{}", httpPost.toString()); } } finally { EntityUtils.consumeQuietly(response.getEntity()); } return true; } });
DefaultHttpClient httpClient = new DefaultHttpClient(); HttpResponse res = httpClient.execute(request); Log.i("Request", request.toString()); } catch (Exception e) { e.printStackTrace();
stringEntity.setContentType( PwmConstants.AcceptValue.json.getHeaderValue() ); httpPost.setEntity( stringEntity ); LOGGER.debug( () -> "beginning external rest call to: " + httpPost.toString() + ", body: " + jsonRequestBody ); httpResponse = PwmHttpClient.getHttpClient( pwmApplication.getConfig() ).execute( httpPost ); final String responseBody = EntityUtils.toString( httpResponse.getEntity() );
Log.info("REGISTER USER: ", httpPost.toString()); Log.info("REGISTER USER: ", "Response: " + EntityUtils.toString(resp.getEntity(), "UTF-8")); } catch (URISyntaxException | IOException e) {
Log.info("CONTENT PUSH: ", "Content posted to: " + httpPost.toString()); Log.info("CONTENT PUSH: ", "Response: " + EntityUtils.toString(resp.getEntity(), "UTF-8")); } catch (ClientProtocolException e) {