php POST送信時の「Content-type not specified assuming application/x-www-form-urlencoded」エラー

phpでフォームを使わずに直接POST送信したら
「Content-type not specified assuming application/x-www-form-urlencoded」
というエラーが出たのでコードを修正した際のメモ。

これはデータ送信する際のheaderが足りない!という内容のエラーらしい。エラー前は↓のような感じでメソッドタイプとデータを渡してPOSTした。

$data =array(
	'param1' => $param1,
	'param2' => $param2
);
					
$data = http_build_query($data, "", "&");
					
$options =array(
	'http' =>array(
			'method' => 'POST',
			'content' => $data
		)
	);

$contents =file_get_contents($url, false, stream_context_create($options));

修正後は、$optionsの配列にヘッダーを設定。こうすることでエラーが無くなり無事送信完了。

$data =array(
	'param1' => $param1,
	'param2' => $param2
);
					
$data = http_build_query($data, "", "&");

$header = array(
		"Content-Type: application/x-www-form-urlencoded",
		"Content-Length: ".strlen($data)
	);
					
$options =array(
	'http' =>array(
			'method' => 'POST',
			'header' => implode("\r\n", $header),
			'content' => $data
		)
	);

$contents =file_get_contents($url, false, stream_context_create($options));



TextViewのフォーカスを有効にする

androidのTextViewでフォーカスを有効にしようと思ったけど、うまく行かなかったのでメモ。

xmlで普通に↓「focusable」をtrueにすればいいだけかと思っていたらうまく行かなかった。

<TextView
  android:layout_width="fill_parent"
  android:layout_height="wrap_content"
  android:text="てきすと"
  android:focusable="true"
  />

↓のように「focusable」と「focusableInTouchMode」をtrueにするとうまく行った。

<TextView
  android:layout_width="fill_parent"
  android:layout_height="wrap_content"
  android:text="てきすと"
  android:focusable="true"
  android:focusableInTouchMode="true"
  />

「focusableInTouchMode」はTouchモード時にViewがフォーカスを取得可能か設定するオプションとのこと。