Tag: post

将图像发布到Tumblr API

所以我正在编写一个小型Java应用程序,使用他们提供的API将图像目录转储到用户的tumblr博客中: http : //www.tumblr.com/docs/en/api 我已经发布明文了,但现在我需要找出如何在POST中发送图像文件。 我的代码目前正在返回403禁止错误,我尝试的其他所有内容都给我一个错误的请求错误。 如果可以的话,我宁愿不必使用外部库。 这是我的ImagePost类: import java.io.*; import java.net.*; public class ImagePost { String data = null; String enc = “UTF-8”; String type; File img; byte[] bytes; FileReader reader; ByteArrayOutputStream bytesOut; public ImagePost(String imgPath, String caption, String tags) throws IOException { //Construct data type = “photo”; img = new File(imgPath); bytes = […]

Java HTTP Post Applet服务器 – 内部生成的Image

我在applet中使用J2D创建了一个BufferedImage。 我想使用HTTP Post @ http:// localhost:3001 / upload / file上传这个BufferedImage。 编辑:我有一个ROR服务器处理服务器的东西,我正在寻找客户端的Java代码。 我能找到的所有例子都涉及上传文件。 有谁知道如何上传BufferedImage? 干杯, slotishtype

Android – 来自Map 的HttpURLConnection参数通过POST方法

这只是问答。 仅仅意味着一个维基百科。 我经常搜索以实现这一目标。 所有人都发布了不同类型的答案。 我现在成功使用此代码。 所以我想与所有人分享。 您的HttpURLConnection必须位于异步任务(doInBackground)中。 脚步: 在Map Function中设置参数 在表单中构建字符串: param=val&param2=val2 设置HttpUrlConnection OutputStream用于OutputStream 。 使用InputStream从服务器读取响应 设置参数: Map params = new LinkedHashMap(); params.put(“tag”, “sda”); try { StringBuilder postData = new StringBuilder(); for (Map.Entry param : params.entrySet()) { if (postData.length() != 0) postData.append(‘&’); postData.append(URLEncoder.encode(param.getKey(), “UTF-8”)); postData.append(‘=’); postData.append(URLEncoder.encode(String.valueOf(param.getValue()), “UTF-8”)); } String postdata = postData.toString(); Log.w(“postData”, postdata); //HERE […]

使用Java org.apache.http.client获取重定向URL

在向服务器发帖后,我需要帮助弄清楚如何获取重定向。 首先,我需要从服务器获取一些cookie。 然后我用cookie和其他参数执行post。 然后服务器以302重定向回答。 如何获取该重定向的url? 代码如下所示: HttpGet get = new HttpGet(urlOne); try { //Creating a local instance of cookie store. CookieStore cookieJar = new BasicCookieStore(); // Creating a local HTTP context HttpContext localContext = new BasicHttpContext(); // Bind custom cookie store to the local context localContext.setAttribute(ClientContext.COOKIE_STORE, cookieJar); HttpResponse response = httpClient.execute(get, localContext); HttpEntity entity = […]

将参数添加到Apache HttpPost

我正在尝试将文件发送到Servlet。 除了这个文件,我还必须发送一些参数(即名称/ ID,日期和其他几个)。 我在客户端使用HttpClient,在服务器端使用ServerFileUpload。 这是客户端代码:… String url = “http://localhost:8080/RicezioneServlet/RicezioneServlet”; HttpClient httpclient = new DefaultHttpClient(); HttpPost postMethod = new HttpPost(url); MultipartEntity mpe = new MultipartEntity(); //I’m sending a .zip file ContentBody cb = new FileBody(fileToSend,”application/zip”); mpe.addPart(“file”, cb); postMethod.setEntity(mpe); HttpResponse resp = httpclient.execute(postMethod); HttpEntity respEntity = resp.getEntity(); System.out.println(resp.getStatusLine()); … 在服务器端,我们有: ServletFileUpload sup = new ServletFileUpload(); FileItemIterator it […]

为什么这个简单的SOAP客户端不工作(org.apache.http)?

我想将一个XML文件作为请求发送到SOAP服务器。 这是我的代码:( 使用org.apache.http从使用SOAP操作发送HTTP Post请求进行了修改) import org.apache.http.client.*; import org.apache.http.client.methods.*; import org.apache.http.impl.client.*; import org.apache.http.entity.StringEntity; import org.apache.http.protocol.HTTP; import org.apache.http.HttpResponse; import java.net.URI; public static void req() { try { HttpClient httpclient = new DefaultHttpClient(); String body=”xml here”; String bodyLength=new Integer(body.length()).toString(); URI uri=new URI(“http://1.1.1.1:100/Service”); HttpPost httpPost = new HttpPost(uri); httpPost.setHeader( “SOAPAction”, “MonitoringService” ); httpPost.setHeader(“Content-Type”, “text/xml;charset=UTF-8”); StringEntity entity = new StringEntity(body, […]

如何在具有lazyload scrollLoader.js的站点中使用Jsoup

我有一个关于jsoup的问题因为lazyload scrollLoader.js我用java代码到达网站,我只列出了50个图像名称jsoup.But在网站上向下滚动时,很多图像不断加载。 我的问题是,是否可以将图像数量发布到与Jsoup.connect()一起使用的url中以从网站获取所有图像? 这是网站: http : //www.logowik.com 这是网站中脚本的用法: $(document).ready(function(e) { CalculateColumns(); recordCount = 50; groupID = “0”; catID = “0”; query = “”; userEntry = “”; groupInterval = “0”; AddEvent(window, “resize”, CalculateColumns); document[“scrollLoader”] = new scrollLoader({evn : getGrids, seize : 1}); document[“scrollLoader”].DoScroll(); addLogoClickEvent(); }); 我用以下url发布这些参数: http://www.logowik.com/index.php?g=1&groupID=1&catID=0 : http://www.logowik.com/index.php?g=1&groupID=1&catID=0 recordCount = 50这个url我得到50张图片,因为recordCount = 50在script 。 但我无法将此参数发布到url。 […]

Java Servlet – 获取具有相同名称的参数

我知道我可以获得如下参数: HTML Servlet的 String field = request.getParameter(“field”); 但是,如果我有多个具有相同名称的输入,例如: HTML 在PHP中我可以使用name=”line[]”来获取所有行输入的数组。 但是如何在java中解决这个问题呢? Servlet伪代码 String[] lines = request.getParameterArray(“line”); for(String line : lines){ //do shit }

将图像从Android客户端发送到AppEngine Cloud Endpoint

我正在使用AppEngine后端开发Android应用程序。 我正在使用Java中的Google Cloud Endpoints创建服务器部分。 我的问题是我无法从客户端向服务器发送位图。 我使用了这个问题的答案,但即使客户端部分似乎没有任何问题,服务器部分也根本不接收数据。 我也认为这个解决方案可能有点复杂,它可能会以不同的,更简单的方式工作,但这是我第一次实现服务器并第一次向它发送图片,所以我接受任何有关此的好建议。 谢谢! 这是我的代码: String boundary = Long.toHexString(System.currentTimeMillis()); // Just generate some unique random value. String CRLF = “\r\n”; // Line separator required by multipart/form-data. String charset = “UTF-8”; HttpURLConnection connection = (HttpURLConnection) new URL(“https://path_to_my_app/_ah/api/registration/v1/uploadImage”).openConnection(); connection.setDoOutput(true); connection.setReadTimeout(60000); connection.setRequestMethod(“POST”); connection.setRequestProperty(“Content-Type”, “multipart/form-data; boundary=” + boundary); PrintWriter writer = null; try { OutputStream […]

使用POST发送JSON对象时的HTTP 415

import java.io.BufferedReader; import java.io.InputStreamReader; import java.net.HttpURLConnection; import java.net.URL; import java.io.DataOutputStream; import java.io.InputStream; public class TestingPost { public static void main(String args[]) { URL url; HttpURLConnection connection = null; String targetURL=”…..”;//here is my local server url String urlParameters=”{\”clubhash\”:\”100457d41b9-ab22-4825-9393-ac7f6e8ff961\”,\”username\”:\”anonymous\”,\”message\”:\”simply awesome\”,\”timestamp\”:\”2012/11/05 13:00:00\”}”; try { //Create connection url = new URL(targetURL); connection = (HttpURLConnection)url.openConnection(); connection.setRequestMethod(“POST”); connection.setRequestProperty(“Content-Type”, “application/x-www-form-urlencoded”); connection.setRequestProperty(“Content-Length”, “” […]