/** * Adds a text field part * * @param parameterName The name of the parameter. * @param parameterValue The value of the parameter. */ public void addParameter(String parameterName, String parameterValue) { LOG.trace("enter addParameter(String parameterName, String parameterValue)"); Part param = new StringPart(parameterName, parameterValue); parameters.add(param); }
PostMethod httpPost = new PostMethod(url.toString()); try { Part[] parts = {new StringPart(schema.getSchemaName(), schema.toString())}; MultipartRequestEntity requestEntity = new MultipartRequestEntity(parts, new HttpMethodParams()); httpPost.setRequestEntity(requestEntity);
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 static PutMethod sendMultipartPutRequest(String url, String body) throws IOException { HttpClient httpClient = new HttpClient(); PutMethod putMethod = new PutMethod(url); // our handlers ignore key...so we can put anything here Part[] parts = {new StringPart("body", body)}; putMethod.setRequestEntity(new MultipartRequestEntity(parts, putMethod.getParams())); httpClient.executeMethod(putMethod); return putMethod; } }
/** * Adds a text field part * * @param parameterName The name of the parameter. * @param parameterValue The value of the parameter. */ public void addParameter(String parameterName, String parameterValue) { LOG.trace("enter addParameter(String parameterName, String parameterValue)"); Part param = new StringPart(parameterName, parameterValue); parameters.add(param); }
/** * Adds a text field part * * @param parameterName The name of the parameter. * @param parameterValue The value of the parameter. */ public void addParameter(String parameterName, String parameterValue) { LOG.trace("enter addParameter(String parameterName, String parameterValue)"); Part param = new StringPart(parameterName, parameterValue); parameters.add(param); }
/** * Adds a text field part * * @param parameterName The name of the parameter. * @param parameterValue The value of the parameter. */ public void addParameter(String parameterName, String parameterValue) { LOG.trace("enter addParameter(String parameterName, String parameterValue)"); Part param = new StringPart(parameterName, parameterValue); parameters.add(param); }
/** * Adds a text field part * * @param parameterName The name of the parameter. * @param parameterValue The value of the parameter. */ public void addParameter(String parameterName, String parameterValue) { LOG.trace("enter addParameter(String parameterName, String parameterValue)"); Part param = new StringPart(parameterName, parameterValue); parameters.add(param); }
public void endOnline(String redirectLink) throws IOException { String uri = address + "api/active/receiver/stop/"; LinkedList<Part> partsList = new LinkedList<>(); partsList.add(new StringPart("redirect", redirectLink)); multipartPost(partsList, uri, HttpStatus.SC_RESET_CONTENT); }
public String startOnline() throws IOException { String uri = address + "api/active/receiver/start/"; LinkedList<Part> partsList = new LinkedList<>(); partsList.add(new StringPart("token", token)); partsList.add(new StringPart("projectKey", project)); partsList.add(new StringPart("title", title)); String[] res = multipartPost(partsList, uri, HttpStatus.SC_CREATED); JSONObject obj = JSONObject.fromObject(res[0]); return address + "gui/active/" + obj.optString("OnlineID", "N/A") + "/"; }
public void sendOnlineData(JSONArray data) throws IOException { String uri = address + "api/active/receiver/data/"; LinkedList<Part> partsList = new LinkedList<>(); String dataStr = data.toString(); log.debug("Sending active test data: " + dataStr); partsList.add(new StringPart("data", dataStr)); multipartPost(partsList, uri, HttpStatus.SC_ACCEPTED); }
HttpClient httpclient = new DefaultHttpClient(); HttpPost httppost = new HttpPost("http://www.yourhost.com"); MultipartEntity entity = new MultipartEntity(); entity.addPart(new StringPart("name", "yourname")); File imageFile = // .. get your image file entity.addPart(new FilePart("picture", imageFile, null, "image/jpeg")); httppost.setEntity(entity); HttpResponse httpResponse = httpclient.execute(httppost);
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; }
File f = new File("/path/fileToUpload.txt"); HttpRequest request = new HttpRequest("http://host/some_path"); Part[] parts = { new StringPart("param_name", "value"), new FilePart(f.getName(), f) }; filePost.setEntity( new MultipartRequestEntity(parts, filePost.getParams()) ); HttpClient client = new HttpClient(); int status = client.executeMethod(filePost);
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("/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);
private StringPart createStringPart(String name, String value) { StringPart stringPart = new StringPart(name, value); stringPart.setContentType(null); stringPart.setTransferEncoding(null); stringPart.setCharSet("UTF-8"); return stringPart; }
private Part[] createParts(WeiXinHttpUpload upload) { if (upload.getFormName() == null) { Part[] parts = {new FileObjectPart(upload.getFileName(), upload.getFileObject(), null, null)}; return parts; } else { Part[] parts = {new FileObjectPart(upload.getFileName(), upload.getFileObject(), null, null), new StringPart(upload.getFormName(), upload.getContent())}; return parts; } }