はてなハイクのAPIのstatuses/update
statuses/update
はてなハイク - API
新しいエントリーを投稿します。画像ファイルを投稿 (file パラメータを指定) する場合は、multipart/form-data でエンコードして下さい。
って書かれていて、バイナリファイルは投稿しないからXMLHttpRequestのsetRequestHeader("Content-Type","application/x-www-form-urlencode")
は必要ないのかなと思っていたけど、必要みたいね。
今のところのソース(一部)
function postComment(data){ var url = "http://h.hatena.ne.jp/api/statuses/update.json"; var user = "teramako"; var password = "hogehoge"; var query = [param +"="+ encodeURIComponent(data[param]) for (param in data)].join("&"); var xhr = new XMLHttpRequest(); xhr.moxBackgroundRequest = false; xhr.open("POST", url, true, user, password); xhr.setRequestHeader("Content-Type","application/x-www-form-urlencoded"); xhr.onreadystatechange = function(){ if (xhr.readyState == 4 && xhr.status != 200){ alert(xhr.status,true); } } xhr.send(query); }