1 |
curl --basic --user username:password -d "" http://kutayzorlu.com/test/login |
1 |
curl --basic --user username:password -d "" http://kutayzorlu.com/test/login |
Apache HttpClient
1 2 3 |
HttpClient client = factory.getHttpClient(); //or any method to get a client instance Credentials credentials = new UsernamePasswordCredentials(username, password); client.getState().setCredentials(AuthScope.ANY, credentials); |
1 2 3 4 5 |
CredentialsProvider credentialsProvider = new BasicCredentialsProvider(); credentialsProvider.setCredentials(AuthScope.ANY, new UsernamePasswordCredentials("username", "password")); CloseableHttpClient httpClient = HttpClientBuilder.create().setDefaultCredentialsProvider(credentialsProvider).build(); |
imports
1 2 3 4 5 6 7 |
import org.apache.http.HttpEntity; import org.apache.http.HttpResponse; import org.apache.http.auth.AuthScope; import org.apache.http.auth.UsernamePasswordCredentials; import org.apache.http.client.methods.HttpGet; import org.apache.http.impl.client.DefaultHttpClient; import org.apache.http.util.EntityUtils; |
Example
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 |
HttpClient client = new HttpClient(); HttpMethod method = new GetMethod(TESTURL); HostConfiguration config = client.getHostConfiguration(); config.setProxy(PROXY_HOST, PROXY_PORT); String username = "Kutay"; String password = "Zorlu"; Credentials credentials = new UsernamePasswordCredentials(username, password); AuthScope authScope = new AuthScope(PROXY_HOST, PROXY_PORT); client.getState().setProxyCredentials(authScope, credentials); client.getState().setCredentials(AuthScope.ANY, credentials); try { client.executeMethod(method); String response = method.getResponseBodyAsString(); if (method.getStatusCode() == HttpStatus.SC_OK) { response = method.getResponseBodyAsString(); } } catch (IOException e) { e.printStackTrace(); } finally { method.releaseConnection(); } |
Example 2
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 |
try { DefaultHttpClient httpclient = new DefaultHttpClient(); httpclient.getCredentialsProvider().setCredentials( new AuthScope(AuthScope.ANY_HOST, AuthScope.ANY_PORT), new UsernamePasswordCredentials("kutay", "zorlu")); HttpPost httppost = new HttpPost("http://kutayzorlu.com:post/test/login"); System.out.println("executing request " + httppost.getRequestLine()); HttpResponse response; response = httpclient.execute(httppost); HttpEntity entity = response.getEntity(); System.out.println("----------------------------------------"); System.out.println(response.getStatusLine()); if (entity != null) { System.out.println("Response content length: " + entity.getContentLength()); } if (entity != null) { entity.consumeContent(); } httpclient.getConnectionManager().shutdown(); } catch (ClientProtocolException e) { // TODO Auto-generated catch block e.printStackTrace(); } catch (IOException e) { // TODO Auto-generated catch block e.printStackTrace(); } |
Example 3_
1 2 3 4 5 6 |
HttpPost httppost = new HttpPost(postData); CookieStore cookieStore = new BasicCookieStore(); BasicClientCookie cookie = new BasicClientCookie("JSESSIONID", getSessionId()); cookieStore.addCookie(cookie); client.setCookieStore(cookieStore); response = client.execute(httppost); |
1 2 3 4 5 |
HttpContext localContext = new BasicHttpContext(); localContext.setAttribute(ClientContext.COOKIE_STORE, cookieStore); response = client.execute(httppost, localContext); |
1 2 3 4 5 6 7 8 9 |
HttpPost httppost = new HttpPost(postData); CookieStore cookieStore = new BasicCookieStore(); BasicClientCookie cookie = new BasicClientCookie("JSESSIONID", getSessionId()); cookie.setDomain("kutayzorlu.com"); cookie.setPath("/posts"); cookieStore.addCookie(cookie); client.setCookieStore(cookieStore); response = client.execute(httppost); |
IKVM.NET is an implementation of Java for Mono and the Microsoft .NET Framework. It includes the following components:
A Java Virtual Machine implemented in .NET
A .NET implementation of the Java class libraries
Tools that enable Java and .NET interoperability
Read more about what you can do with IKVM.NET
https://sourceforge.net/projects/ikvm/files/
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 |
public class LoginServlet extends HttpServlet { private static final long serialVersionUID = 1L; private final String userID = "test"; private final String password = "test"; protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { // get request parameters for userID and password String user = request.getParameter("user"); String pwd = request.getParameter("pwd"); if(userID.equals(user) && password.equals(pwd)){ Cookie loginCookie = new Cookie("user",user); //setting cookie to expiry in 40 mins loginCookie.setMaxAge(40*60); response.addCookie(loginCookie); response.sendRedirect("LoginSuccess.jsp"); } else { RequestDispatcher rd = getServletContext().getRequestDispatcher("/login.html"); PrintWriter out= response.getWriter(); out.println("<font color=red>Either user name or password is wrong.</font>"); rd.include(request, response); } } |
GetCookies
1 2 3 4 5 6 |
String userName = null; Cookie[] cookies = request.getCookies(); if(cookies !=null){ for(Cookie cookie : cookies){ if(cookie.getName().equals("user")) userName = cookie.getValue(); } |
Logout Example
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 |
response.setContentType("text/html"); Cookie loginCookie = null; Cookie[] cookies = request.getCookies(); if(cookies != null) { for(Cookie cookie : cookies){ if(cookie.getName().equals("user")){ loginCookie = cookie; break; } } if(loginCookie != null){ loginCookie.setMaxAge(0); response.addCookie(loginCookie); } response.sendRedirect("login.html"); } |
http://www.luxand.com/facesdk/
Web Distributed Authoring and Versioning (WebDAV), an extension to the HTTP-protocol,
allows authoring of resources on a remote web server.
davfs2 provides the ability to access such resources like a typical filesystem,
allowing for use by standard applications with no built-in support for WebDAV.
davfs2 is designed to fully integrate into the filesystem semantics of Unix-like systems (mount, umount, etc.).
davfs2 makes mounting by unprivileged users as easy and secure as possible.
davfs2 does extensive caching to make the file system responsive, to avoid unnecessary network traffic
and to prevent data loss, and to cope for slow or unreliable connections.
davfs2 will work with most WebDAV servers needing little or no configuration.
davfs2 is developed and tested on GNU/Linux but porting to other free operating systems should not be too cumbersome.
Projects That OneDrive Supports
Ref: http://savannah.nongnu.org/projects/davfs2
rkz