11 android Postの方式で登録します。

1097 ワード

/**
	 * POST         
	 * @param username
	 * @param password
	 * @return
	 */
	public static String loginByPost(String username,String password)
	{
		try{
		String path="http://1902......./web/LoginServlet";
		URL url =new URL(path);
		HttpURLConnection conn=(HttpURLConnection)url.openConnection();
		conn.setConnectTimeout(5000);
		conn.setRequestMethod("POST");
		//    
		String data="username"+username+"&passwor"+password;
		conn.setRequestProperty("Content-Type", "application-www-form-urlencoded");
		conn.setRequestProperty("Content-Length", data.length()+"");
		//post                    
		conn.setDoOutput(true);
		OutputStream os=conn.getOutputStream();
		os.write(data.getBytes());
		
		int code=conn.getResponseCode();
		if(code==200)
		{
			//    
		InputStream is	=conn.getInputStream();
		String text=StreamTools.readInputStream(is);
		return text;
		}
		else
		{
			return null;
		}
		
		}catch(Exception e)
		{
			e.printStackTrace();
			 return null;
		}
     
	}
	
	
	
}