Titanium JIRA Archive
Titanium SDK/CLI (TIMOB)

[TIMOB-17284] Android: HTTPClient.open() parity issue with "method" parameter

GitHub Issuen/a
TypeBug
PriorityLow
StatusOpen
ResolutionUnresolved
Affected Version/sRelease 3.3.0
Fix Version/sn/a
ComponentsAndroid
Labelsn/a
ReporterTony Lukasavage
AssigneeUnknown
Created2014-07-08T15:15:07.000+0000
Updated2018-02-28T20:03:36.000+0000

Description

problem

When passing the method property to HTTPClient.open() on iOS the method can be either upper or lower case. For example, both get and GET would both work for a GET request. On Android, though, only GET would work. If you use get, you get something along the lines of this error (when targeting "google.com" for example):
[ERROR] TiHttpClient: (TiHttpClient-1) [678,678] HTTP Error (org.apache.http.client.HttpResponseException): Method Not Allowed
[ERROR] TiHttpClient: org.apache.http.client.HttpResponseException: Method Not Allowed
[ERROR] TiHttpClient: 	at ti.modules.titanium.network.TiHTTPClient$LocalResponseHandler.handleResponse(TiHTTPClient.java:259)
[ERROR] TiHttpClient: 	at ti.modules.titanium.network.TiHTTPClient$LocalResponseHandler.handleResponse(TiHTTPClient.java:218)
[ERROR] TiHttpClient: 	at org.apache.http.impl.client.AbstractHttpClient.execute(AbstractHttpClient.java:657)
[ERROR] TiHttpClient: 	at org.apache.http.impl.client.AbstractHttpClient.execute(AbstractHttpClient.java:637)
[ERROR] TiHttpClient: 	at ti.modules.titanium.network.TiHTTPClient$ClientRunnable.run(TiHTTPClient.java:1291)
[ERROR] TiHttpClient: 	at java.lang.Thread.run(Thread.java:841)
[ERROR] (405) Method Not Allowed
[ERROR] <!DOCTYPE html>
[ERROR] <html lang=en>
[ERROR] <meta charset=utf-8>
[ERROR] <meta name=viewport content="initial-scale=1, minimum-scale=1, width=device-width">
[ERROR] <title>Error 405 (Method Not Allowed)!!1</title>
[ERROR] <style>
[ERROR] *{margin:0;padding:0}html,code{font:15px/22px arial,sans-serif}html{background:#fff;color:#222;padding:15px}body{margin:7% auto 0;max-width:390px;min-height:180px;padding:30px 0 15px}* > body{background:url(//www.google.com/images/errors/robot.png) 100% 5px no-repeat;padding-right:205px}p{margin:11px 0 22px;overflow:hidden}ins{color:#777;text-decoration:none}a img{border:0}@media screen and (max-width:772px){body{background:none;margin-top:0;max-width:none;padding-right:0}}#logo{background:url(//www.google.com/images/errors/logo_sm_2.png) no-repeat}@media only screen and (min-resolution:192dpi){#logo{background:url(//www.google.com/images/errors/logo_sm_2_hr.png) no-repeat 0% 0%/100% 100%;-moz-border-image:url(//www.google.com/images/errors/logo_sm_2_hr.png) 0}}@media only screen and (-webkit-min-device-pixel-ratio:2){#logo{background:url(//www.google.com/images/errors/logo_sm_2_hr.png) no-repeat;-webkit-background-size:100% 100%}}#logo{display:inline-block;height:55px;width:150px}
[ERROR] </style>
[ERROR] <a href=//www.google.com/><span id=logo aria-label=Google></span></a>
[ERROR] <p><b>405.</b> <ins>That’s an error.</ins>
[ERROR] <p>The request method <code>get</code> is inappropriate for the URL <code>/</code>.  <ins>That’s all we know.</ins>

test case

var client = Ti.Network.createHTTPClient({
	onload : function(e) {
		Ti.API.info(this.responseText);
	},
	onerror : function(e) {
		return Ti.API.error('(' + this.status + ') ' + e.error + '\n' + this.responseText);
	}
});

client.open('get', 'http://google.com'); // change to "GET" and android will work
client.send();

expected

Android method for HTTPClient.open() should be allowed to be specified in upper or lower case.

actual

Android calls end in error if method is lowercase.

Comments

  1. Neeraj Gupta 2014-07-08

    [~ingo] FYI
  2. Ingo Muschenetz 2014-07-08

    It appears it might be related to https://github.com/appcelerator/titanium_mobile/blob/7724a0083693811d93b74c6c2b98f956fb8edfff/android/modules/network/src/java/ti/modules/titanium/network/TiHTTPClient.java#L1110.
  3. Neeraj Gupta 2014-07-08

    Yeah. Looks like it.

JSON Source