MoyaSystem

もやしです。

Titanium Mobile からWordPressにログインする方法

POSTリクエストでWordPressにログインするには

method: POST
URL: http://yourwordpress.com/wp-login.php
data: {
"log": "username",
"pwd": "password"
}

とすればOK。

Titanium Mobile では

index.js

function login(){
	var url = 'http://yourwordpress.com/wp-login.php';
	var loginClient = Ti.Network.createHTTPClient({
		onload: function(e){
			if(this.responseText.match('login_error')){
				alert('error!');	
			}else{
				alert('login!');
			}
		},
		onerror: function(e){
			Ti.API.debug("error:" + e.error);
		},
		timeout: 5000
	});
	loginClient.open("POST", url);
	loginClient.send({
		'log': $.userId.value,
		'pwd': $.password.value
	});
}
$.index.open();

index.xml

<Alloy>
	<Window class="container">
		<TextField id="userId" color="#336699" top="10" left="10" hintText="ユーザ名"/>
		<TextField id="password" color="#336699" top="100" left="10" hintText="パスワード"/>
		<Button id="loginBtn" title="ログイン" onClick="login" top="170" width="150" height="60" />
	</Window>
</Alloy>

みたいにすればできる。
ただログインの成否の条件がこれではあまりにあんまりなので正攻法がなんなのかご存知のかたおしえてください……