用java实现一个http get请求。

代码大概如下

private void getMethod()
{
String httpUrl= “http://wdou.cn/luo/a.php”;
// HttpGet连接对象
HttpGet httpRequest = new HttpGet(httpUrl);
try {
// 取得HttpClient对象
HttpClient httpclient = new DefaultHttpClient();
// 请求HttpClient,取得HttpResponse
HttpResponse httpResponse = httpclient.execute(httpRequest);
// 请求成功
if (httpResponse.getStatusLine().getStatusCode() == HttpStatus.SC_OK) {
// 取得返回的字符串
String strResult = EntityUtils.toString(httpResponse
.getEntity());
textview1.setText(strResult);
} else {
textview1.setText(“请求错误!”);
}
} catch (Exception e) {
e.printStackTrace();
}
}
使用php实现,只需要file_get_contents(“http://xxx.com/a.php”)
实在是反人类啊。。
一开始一直报错,就是throw exceptions。一大堆也看不懂,应该是function的位置不对,好像是忘记了this的原因。activity的代码:

public class LuoActivity extends Activity
{
/** Called when the activity is first created. */
private TextView textview1;
private Button button1;
@Override
public void onCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
final TextView textview1=(TextView)findViewById(R.id.textview1);
textview1.setText(“caooooooo”);
Button button1=(Button)findViewById(R.id.button1);
button1.setOnClickListener(new Button.OnClickListener()
{
public void onClick (View v)
{
this.getMethod();
}
}

需要记住的类好多,不知道有什么好方法记住。

发表在 笔记 | 留下评论

联想u350 无法关机的解决办法

表现:关机,一直在 正在关机。。。
就卡掉了 ,无法断电

打开记事本,并输入下列内容(也可以复制^_^):
net stop “Audiosrv”
netstop”AudioEndpointBuilder”
2)在记事本的“文件”菜单,选择“另存为”,保存类型为“所有文件”,文件名随便起,例如“Audiostop.bat”(我起的是stopaudio.bat),保存到任务目录(最好为英文目录)
3)在开始菜单的附件打开“运行”输入”gpedit.msc”,“用户配置”>“Windows设置”>“脚本(登录/注销)”>“注销”
4)双击注销,在弹出的属性窗口点击“添加”,选择刚才生成的文件,按确定。
5)在“注销”的属性窗口点击应用,关闭。

发表在 笔记 | 留下评论

mysql表修复

服务器遭遇数据不能显示问题。进去mysql,发现表不能打开。提示
xx is marked as crashed and should be repaired.
下载mysqlchk,修复失败。
下载myisamchk,先关闭mysql
net stop mysql
然后进入要修复的表的目录
cd e:/appserv/mysql/data/xxxx
myisam -r tablename

显示
E:\AppServ\MySQL\data\
- recovering (with
Data records: 636
- Fixing index 1
- Fixing index 2
- Fixing index 3
- Fixing index 4
- Fixing index 5
- Fixing index 6
- Fixing index 7
- Fixing index 8
- Fixing index 9
- Fixing index 10
- Fixing index 11
然后就好啦!

发表在 php, 分享 | 标签为 , , | 留下评论

骑士cms(74cms)最新v3.1 ucenter同步修改版

折腾了好几天,把最新的骑士cms 3.1 添加了ucenter功能。
这个更新日志里写了新版提供ucenter整合了,却没发现 应该是企业版的功能吧

目前实现了:
用户登陆 激活 修改密码 注册
未实现:
短消息整合 同步登陆退出 积分整合

凑合能用,用户名 密码 email跟ucenter是同步的
激活就是ucenter中存在的用户,在别的程序注册的,在骑士cms中没有,激活后就有了

修改文件列表:
/include/fun_user.php
/user/user_company.php
/user/user_personal.php
/user/user_uc_functions.php
/plus/ajax.php
/data/config.php

仅供学习使用,商业用途请联系74cms团队

any questions:xiaotianhu2#gmail.com

下载地址:http://rainyluo.com/74cmsv31.zip

发表在 php | 2 条评论

php 删除文件中的行(端落)

折腾了一下,php本身没有删除文件中某几行的函数
只能先把文件读入到数组 ,处理完再写回去。
可以自己写个cli,写个比较完善的php处理文件的交互脚本了。

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
 
<?php
$file="/Applications/XAMPP/htdocs/a.txt";
$line_start="1";
$line_end="3";
delete_line($file,$line_start,$line_end);
function delete_line($file,$line_to_delete_s,$line_to_delete_e)
{
	$f=file($file);
	foreach ($f as $key=>$value)
	{
		if ($key<=$line_to_delete_e&&$key>=$line_to_delete_s)
		{
			echo "line".$key."was deleted.</br>";
			continue;
		}
		else
		{
			$newfile.=$value;
		}
	}
	$f=fopen($file,'w');
	$r=fwrite($f,$newfile);
	fclose($f);
}
?>
发表在 php | 一条评论

php遍历目录文件

憋了老半天,写了个简单的遍历目录文件的小段代码
算法好重要啊。现在虽然不熟,勤能补拙。
目录没有缩进的效果。。先不弄了

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
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
<?php
$dir="/Applications/XAMPP/htdocs/74cms/upload/";
foreach_array($dir);
/*
 * read dir
 * return dirlist in array
 */
function rdir($pwd)
{
 
	if (!is_dir($pwd))
	{
		return false;
	}
	$dir_handle=opendir($pwd);
	$i=0;
	while($dir_res=readdir($dir_handle)){
		$dirlist[$i]=$dir_res;
		$i++;
	}
	closedir($dir_handle);
	return $dirlist;
}
/*
 * print a string
 */
function printdir($string,$isfile=1)
{
	if ($isfile==1)
	{
		echo $string."</br>";
	}
	else if ($isfile!=1)
	{
		echo "<font color='red'>".$string."</br></font>";
		echo "</br>";
	}
}
/*
 * foreach an array to check if is dir
 * 
 */
function foreach_array($path)
{
	global $dir;
	$array=rdir($path);
	if ($array)
	{
	foreach ($array as $value)
	{
		if (strpbrk($value,"."))
		{
			printdir($value);
		}
		else
		{
			printdir($value,0);
			$sub_dir=$path.$value."/";
			foreach_array($sub_dir);
		}
	}
	}
}
发表在 php | 留下评论

php的变量引用与unset

看这样一段代码:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
<?php
 
function indexAction()
{
    $arr = array(1,2,3,4,5);
    delete($arr);
    print_r($arr);
}
 
 
function delete(&$arr1)
{
    unset($arr1);
 
}
indexAction();

想通过delete函数来删除$arr数组,所以传递一个引用,使得两个变量指向相同再unset
但是uset的功能是:

取消引用
当你 unset 一个引用,只是断开了变量名和变量内容之间的绑定。这并不意味着变量内容被销毁了。例如:

$a = 1;
$b =& $a;
unset ($a);
?>

不会 unset $b,只是 $a。

所以不会成功。只是取消了引用,变量内容不会没有。

在c++中,函数参数是数组时,是按照引用传递的,函数改变实参的值,则实参是会变化的
但php默认情况下不是,改变实参的值,是不会变化的。

1
2
3
4
5
6
7
8
$arr=array (0,1,2,3,4,5);
change($arr);
print_r ($arr);
function change($arr)
{
 
	$arr[2]=10;
}

结果:
Array ( [0] => 0 [1] => 1 [2] => 2 [3] => 3 [4] => 4 [5] => 5 )

修改为按引用传递:

1
2
3
4
5
6
7
8
$arr=array (0,1,2,3,4,5);
change($arr);
print_r ($arr);
function change(&$arr)
{
 
	$arr[2]=10;
}

结果:
Array ( [0] => 0 [1] => 1 [2] => 10 [3] => 3 [4] => 4 [5] => 5 )

发表在 php | 标签为 | 一条评论

wr841n脱机bt折腾记录

为了能在u盘上安装程序,尝试无数。
首先尝试block-mount+block-extroot
根据教程
opkg update
opkg install block-mount
然后要把系统文件都复制到卡上
先挂载u盘
mount /dev/sda1 /mnt
然后
mkdir /tmp/root
mount -o bind / /tmp/root
cp -a /tmp/root/* /mnt
这一步就不行了。一复制,就说read-only filesystem.
umount再mount,再复制 I/O error。但是mnt里是有部分文件夹的,说明也不是readonly的阿。折腾了好多次都无果,用scp把/tmp/root拷贝下来,结果过了很久都没结束,4m的rom用了这么久?一看 都800多m了。。一想,可不 循环了。删掉直接拷贝/下的东西,也是错误多多~不行

我就是想把transmission装在卡上阿。谷歌之,opkg是有这个能力的。根据官网wiki:

http://wiki.openwrt.org/doc/techref/opkg

挂载mount /dev/sda1 /mnt
修改/etc/opkg.conf
添加
dest usb /opt
option force_space
(后一句是从一个论坛看来的 就加上了)

保存

修改/etc/profile

export PATH=:/opt/bin:/opt/sbin:/opt/usr/bin:/opt/usr/sbin

export LD_LIBRARY_PATH=:/opt/lib:/opt/usr/lib
加上这两行

保存 reboot下。重启,先mount
用opkg install transmission-daemon -d usb
将程序安装到usb存储上。ls /mnt,成功!内牛满面阿!
运行transmission-deamon,找不到。应该是path变量没设置成功。输入export,发现path变量没有。那两句话在我就没成功。修改/etc/profile
把后来添加那两句话删掉
用这一句
export PATH=’/bin:/sbin:/usr/bin:/usr/sbin:/mnt/usr/bin:/mnt/usr/sbin:/mnt/bin:/mnt/sbin’
让命令可以在卡上寻找。
任意位置输入transmission-daemon,可以运行了。但是提示缺少libevent2.0的库,export以下,环境变量里没有卡上的lib库。这个文件在/mnt/usr/lib里
参照刚才方法,修改profile 文件添加
export LD_LIBRARY_PATH=/mnt/lib:/mnt/usr/lib
但是没有成功。直接输入
export LD_LIBRARY_PATH=/mnt/lib:/mnt/usr/lib
在export下,成功了。
运行transmission-daemon ,成功!

ps -ef | grep transmission 看以下pid号
再kill + transmission-daemon的进程号 结束
修改/root/.config/transmission-daemon/settings.json
“rpc-whitelist”: “0.0.0.0″,
“rpc-whitelist-enabled”: false,

安装transmission-web
(每次重启安装前先opkg update下)
输入opkg install transmission-web -d usb
安装成功。

输入transmission-daemon,浏览器输入http://192.168.1.1:9091/
进去发现402:fobbiden了
vi setting.json 发现修改的rpc-whitelist失败了,又变成了原来那两句。。。重试三次依然如此,囧了

用transmission-daemon -f 启动,发现这么两句
[03:07:00.325] Using settings from “/root/.config/transmission-daemon” (daemon.c:488)
[03:07:00.325] Saved “/root/.config/transmission-daemon/settings.json” (bencode.c:1721)

可能是配置文件的位置不对。
kill掉,用transmission-daemon -g /root/.config/transmission/重新指定config的文件夹

再次启动,成功了。403没问题了
但是出现的是 找不到web internace,应该是transmission-web的安装位置问题。再次修改 settings.json,
“rpc-url”: “/mnt/usr/share/transmission/web/”,

顺便把下载文件夹修改了
“incomplete-dir”: “/mnt/Downloads”,
“download-dir”: “/mnt/Downloads”,
再次重启
错误代码:
409: Conflict

Your request had an invalid session-id header.

To fix this, follow these steps:

When reading a response, get its X-Transmission-Session-Id header and remember it
Add the updated header to your outgoing requests
When you get this 409 error message, resend your request with the updated header
This requirement has been added to help prevent CSRF attacks.

X-Transmission-Session-Id: lcrLcENh15MQuDQyFxbse31mldB5fqk8Iy1nobOacKqswW3a

再继续折腾下
成功不远了 ~~

继续折腾:
用transmission-deamon –logfile /mnt/logs.log记录log文件
发现,web的地址还是不对。依然去寻找/usr/share/transmission/了
于是ln过去
ln -s /mnt/usr/share/transmission/ /usr/share/
浏览器http://192.168.1.1:9091/

哦也~~成功鸟
一天一夜的成果阿!赶紧找个种子扔里看看~~

发表在 笔记 | 留下评论

scp下载多个文件

折腾路由,奇怪的问题。
需要用ssh把路由linux系统的文件拿回到本地,用scp。搜了下怎么下载全部文件夹,有个论坛。讨论的特别火热,没人说scp到底该怎么下载文件夹,都是 应该用这个应该用那个。

试了下

scp -r root@192.168.1.1:/tmp/root ~/openwrt

就成功了。囧阿。

发表在 笔记 | 2 条评论

wr841n v7改造usb上openwrt成功

wr841n v7,tp的经典老路由了。

根据网上的教程,勉强搞定了。里面走线一塌糊涂~用3r33的模块供电,所幸usb的接线简单。做工差点,但是能用啊~ 内存跟rom没改,32m应该也够 自己技术有限啊~看着内存那么多脚,搞不好就挂了》》》

装好之后,立马插上u盘。果然不成功。灯亮,而且闪了 线路应该没问题
重刷固件,找了个4m能用usb版本的.挂载,在web的luci里能看到256m的sd卡,但是换了两个u盘,都不认识。ssh上去,sd卡是sda1,输入
mount /dev/sda1 /mnt

错误。invalid argument.换了两个u盘,也是这样。
dmesg看看启动信息,usb能发现。但是不能载入

换了个mp4,/dev里能出sda1。dmesg也没问题,但是挂载依然不能 mp4也成功显示usb读取了

u盘格式化ext3格式,再试。。不成功
sd卡格式化ext3格式。终于成功了

爽啊。开始折腾脱机下载~~

发表在 笔记 | 留下评论