public static PostMethod sendMultipartPostRequest(String url, String body) throws IOException { HttpClient httpClient = new HttpClient(); PostMethod postMethod = new PostMethod(url); // our handlers ignore key...so we can put anything here Part[] parts = {new StringPart("body", body)}; postMethod.setRequestEntity(new MultipartRequestEntity(parts, postMethod.getParams())); httpClient.executeMethod(postMethod); return postMethod; }
public HTTP_VERSION getVersion() { HttpVersion httpVersion = (HttpVersion) postMethod.getParams().getParameter("http.protocol.version"); if (httpVersion == HttpVersion.HTTP_1_1) { return HTTP_VERSION.HTTP1_1; } return HTTP_VERSION.HTTP1_0; } }
public void setCharacterEncoding(String s) { postMethod.getParams().setParameter("http.protocol.content-charset", s); }
public int post(String url, Map<String,String> properties) throws HttpException, IOException { final PostMethod post = new PostMethod(url); post.getParams().setContentCharset("UTF-8"); for(Entry<String, String> e : properties.entrySet()) { post.addParameter(e.getKey(), e.getValue()); } return httpClient.executeMethod(post); }
public PostMethod buildPost(NameValuePair[] args_) { PostMethod method = new PostMethod(ssoCheckUrl); method.getParams().setCookiePolicy(CookiePolicy.DEFAULT); method.setRequestBody(args_); return method; }
public PostMethod buildPost(NameValuePair[] args_) { PostMethod method = new PostMethod(checkAccessTokenUrl); method.getParams().setCookiePolicy(CookiePolicy.DEFAULT); method.setRequestBody(args_); return method; }
PostMethod getJsonUrlRequest() { PostMethod request = new PostMethod(getJsonUrl(this.packId)); List<Part> parts = new ArrayList<Part>(); for (NameValuePair part : this.stringParams.values()) { parts.add(new StringPart(part.getName(), part.getValue(), getCharset().name())); } for (Part part : this.fileParams.values()) { parts.add(part); } request.setRequestEntity(new MultipartRequestEntity(parts.toArray(new Part[parts.size()]), request.getParams())); return request; }
public void setVersion(HTTP_VERSION http_version) { HttpParams params = postMethod.getParams(); switch (http_version) { case HTTP1_0: params.setParameter("http.protocol.version", HttpVersion.HTTP_1_0); break; case HTTP1_1: params.setParameter("http.protocol.version", HttpVersion.HTTP_1_1); break; } }
File f = new File(filePath); PostMethod filePost = new PostMethod(url); Part[] parts = { new FilePart("file", f) }; filePost.setRequestEntity(new MultipartRequestEntity(parts, filePost.getParams())); HttpClient client = new HttpClient(); status = client.executeMethod(filePost); logger.info("upload status: " + status);
File f = new File("/path/fileToUpload.txt"); PostMethod filePost = new PostMethod("http://host/some_path"); Part[] parts = { new StringPart("param_name", "value"), new FilePart(f.getName(), f) }; filePost.setRequestEntity( new MultipartRequestEntity(parts, filePost.getParams()) ); HttpClient client = new HttpClient(); int status = client.executeMethod(filePost);
File f = new File(filePath); PostMethod filePost = new PostMethod(url); Part[] parts = { new FilePart("file", f) }; filePost.setRequestEntity(new MultipartRequestEntity(parts, filePost.getParams())); HttpClient client = new HttpClient(); status = client.executeMethod(filePost);
protected String post(String path, NameValuePair[] data) { PostMethod req = new PostMethod(path); req.setRequestBody(data); req.getParams().setContentCharset("utf-8"); return send(req); }
File file = new File("FileToSend.txt"); HttpClient client = new HttpClient(); String url = "http://www.yourdomain.com/destination.php"; PostMethod postMethod = new PostMethod(url); Part[] parts = {new FilePart(file.getName(), file)}; postMethod.setParameter("name", "value"); // set parameters like this instead in separate call postMethod.setRequestEntity( new MultipartRequestEntity(parts, postMethod.getParams())); int status = client.executeMethod(postMethod);
File f = new File("/path/fileToUpload.txt"); PostMethod filePost = new PostMethod("http://host/some_path"); Part[] parts = { new StringPart("param_name", "value"), new FilePart(f.getName(), f) }; filePost.setRequestEntity( new MultipartRequestEntity(parts, filePost.getParams()) ); HttpClient client = new HttpClient(); int status = client.executeMethod(filePost);
File f = new File(filePath); PostMethod postMessage = new PostMethod(urlString); Part[] parts = { new StringPart("param", "value"), new FilePart(f.getName(), f) }; postMessage.setRequestEntity(new MultipartRequestEntity(parts, postMessage.getParams())); HttpClient client = new HttpClient(); int status = client.executeMethod(postMessage);
File f = new File("/path/fileToUpload.txt"); PostMethod filePost = new PostMethod("http://host/some_path"); Part[] parts = { new StringPart("param_name", "value"), new FilePart(f.getName(), f) }; filePost.setRequestEntity( new MultipartRequestEntity(parts, filePost.getParams()) ); HttpClient client = new HttpClient(); int status = client.executeMethod(filePost);
public String executePost(String url, Map<String, String> parameters, List<UploadItem> uploadItems, IProgressMonitor monitor) throws ReviewboardException { PostMethod postRequest = new PostMethod(stripSlash(location.getUrl()) + url); configureRequestForJson(postRequest); List<Part> parts = new ArrayList<Part>(); for ( Map.Entry<String, String> paramEntry : parameters.entrySet() ) parts.add(new StringPart(paramEntry.getKey(), paramEntry.getValue())); for ( UploadItem uploadItem : uploadItems ) { String partName = uploadItem.getName(); parts.add(new FilePart(partName, new ByteArrayPartSource(uploadItem.getFileName(), uploadItem.getContent()))); } postRequest.setRequestEntity(new MultipartRequestEntity(parts.toArray(new Part[parts.size()]), postRequest.getParams())); return executeMethod(postRequest, monitor); }
@Override void configureRequest(PostMethod method) throws IOException { Part[] parts = new Part[] { new FilePart("bundle", new ByteArrayPartSource("bundle.jar", IOUtils.toByteArray(jarredBundle))) }; method.setRequestEntity(new MultipartRequestEntity(parts, method.getParams())); } }.installBundle();
protected void initHttpHeaders(XmlRpcRequest pRequest) throws XmlRpcClientException { config = (XmlRpcHttpClientConfig) pRequest.getConfig(); method = newPostMethod(config); super.initHttpHeaders(pRequest); if (config.getConnectionTimeout() != 0) client.getHttpConnectionManager().getParams().setConnectionTimeout(config.getConnectionTimeout()); if (config.getReplyTimeout() != 0) client.getHttpConnectionManager().getParams().setSoTimeout(config.getReplyTimeout()); method.getParams().setVersion(HttpVersion.HTTP_1_1); }
protected void initHttpHeaders(XmlRpcRequest pRequest) throws XmlRpcClientException { config = (XmlRpcHttpClientConfig) pRequest.getConfig(); method = newPostMethod(config); super.initHttpHeaders(pRequest); if (config.getConnectionTimeout() != 0) client.getHttpConnectionManager().getParams().setConnectionTimeout(config.getConnectionTimeout()); if (config.getReplyTimeout() != 0) client.getHttpConnectionManager().getParams().setSoTimeout(config.getReplyTimeout()); method.getParams().setVersion(HttpVersion.HTTP_1_1); }