Skip to content

Instantly share code, notes, and snippets.

@ojimac
Created June 4, 2012 04:21
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ojimac/2866333 to your computer and use it in GitHub Desktop.
Save ojimac/2866333 to your computer and use it in GitHub Desktop.
HTTPリクエストした先がBasic認証かかっていたときの対処@TitaniumMobile
// 参考 : http://boydlee.com/appcelerator-titanium/basic-authentication-with-titanium-httpclient-and-json.html
xhr = Ti.Network.createHTTPClient();
xhr.onload = function() {
// snip
};
xhr.onerror = function() {
// snip
};
xhr.open('POST', 'http://example.com');
// NOTE: 'Basic ' の後に半角スペースが必要...
var authstr = 'Basic ' + Ti.Utils.base64encode('user' + ':' + 'pass');
xhr.setRequestHeader('Authorization', authstr);
xhr.send();
@ojimac
Copy link
Author

ojimac commented Jun 4, 2012

Basic認証の際のHTTPヘッダの例
http://x68000.q-e-d.net/~68user/net/http-auth-1.html

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment