Tag: 发布

不可变对象是否对不正当的出版物免疫?

这是JCiP的一个例子。 public class Unsafe { // Unsafe publication public Holder holder; public void initialize() { holder = new Holder(42); } } public class Holder { private int n; public Holder(int n) { this.n = n; } public void assertSanity() { if (n != n) { throw new AssertionError(“This statement is false.”); } } } 在页34: […]

用java登录网站

我想用java登录一个网站。 我使用的是org.apache.http,我已经写好了 HttpClient client = new DefaultHttpClient(); HttpPost post = new HttpPost(“https://accounts.google.com/ServiceLogin? service=mail&passive=true&rm=false&continue=https%3A%2F%2Fmail.google.com%2Fmail%2F%3Fhl%3Dsl%26tab%3Dwm%26ui%3Dhtml%26zy%3Dl&bsv=llya694le36z&scc=1&ltmpl=default&”); try { List nameValuePairs = new ArrayList(1); nameValuePairs.add(new BasicNameValuePair(“vb_login_username”, “XXX”)); nameValuePairs.add(new BasicNameValuePair(“vb_login_password”, “XXX”)); post.setEntity(new UrlEncodedFormEntity(nameValuePairs)); HttpResponse response = client.execute(post); BufferedReader rd = new BufferedReader(new InputStreamReader(response.getEntity().getContent())); String line = “”; while ((line = rd.readLine()) != null) { System.out.println(line); } } catch (IOException e) […]

Java中的HTTP Json请求?

如何用Java生成HTTP Json请求? 任何图书馆? 在“HTTP Json请求”下,我的意思是使用Json对象作为数据进行POST,并将结果作为Json接收。

使用java HTTP POST连接发送图像文件

我正在尝试使用Java HTTP POST请求将图像发送到网站。 我正在使用此处使用的基本代码将文件从Java客户端上传到HTTP服务器 : 这是我的修改: String urlToConnect = “http://localhost:9000/upload”; File fileToUpload = new File(“C:\\Users\\joao\\Pictures\\bla.jpg”); String boundary = Long.toHexString(System.currentTimeMillis()); // Just generate some unique random value. URLConnection connection = new URL(urlToConnect).openConnection(); connection.setDoOutput(true); // This sets request method to POST. connection.setRequestProperty(“Content-Type”, “multipart/form-data; boundary=” + boundary); PrintWriter writer = null; try { writer = new PrintWriter(new OutputStreamWriter(connection.getOutputStream())); […]

Java httpPost成.aspforms

在Java中,如果我想在服务器上发送数据到表单,其中表单类型是: Log in User: Password: Save account 在这种情况下,我必须使用HttpPost方法,因为表单接受方法“post”,因为它在表单定义(初始化)中声明: 在我的例子(Android解决方案)我正在使用 __VIEWSTATE __EVENTTARGET __EVENTARGUMENT ctl00$tbUsername ctl00$tbPwd ctl00$chkRememberLogin ctl00$cmdLogin 值,因为它们是服务器发布post所需的一次。 在没有编程服务器的情况下,我在哪里可以找到服务器所需的内容? 我使用WireShark软件查看客户端和服务器之间的所有响应或传出请求,只需使用httpfilter来查看http事务。 然后使用任何浏览器以通常的方式在线登录,然后在WireShark中,您将看到浏览器和服务器之间的所有请求和响应。 通过已知的IP地址或主机地址找到您感兴趣的那个,然后复制您在任何事务上单击右键时找到的可读字节 。 因此,当您这样做时,您将发现您对服务器的请求必须如何以及需要哪些值。 回到编码(java): public HttpResponse httpPost1(String viewstateValue, String url, String username, String password) throws ConnectTimeoutException { try { // ——–post HttpPost httppost = new HttpPost(url); List nameValuePairs = new ArrayList(); nameValuePairs.add(new BasicNameValuePair(“__VIEWSTATE”, viewstateValue)); nameValuePairs.add(new […]