[AC-2447] POST Request does not send Parameter
GitHub Issue | n/a |
---|---|
Type | Bug |
Priority | n/a |
Status | Closed |
Resolution | Cannot Reproduce |
Resolution Date | 2014-01-20T07:54:16.000+0000 |
Affected Version/s | n/a |
Fix Version/s | n/a |
Components | n/a |
Labels | n/a |
Reporter | Johannes Weber |
Assignee | Shak Hossain |
Created | 2013-12-27T21:01:09.000+0000 |
Updated | 2016-03-08T07:41:29.000+0000 |
Description
Steps to Reproduce
Hi, I have problems to send parameter via POST HTTPRequest. The url is called but no parameter are send ;-/ The posttestserver answers every time: No Post Params. Empty post body. Here my configuration: Titanium Studio, build: 3.2.0.201312191547 and my source code snipplet: var loginReq = Titanium.Network.createHTTPClient(); function doClick(e) { if ($.username.value != '' && $.password.value != '') { loginReq.open('POST','http://posttestserver.com/post.php'); var params = { username: $.username.value, password: Ti.Utils.md5HexDigest($.password.value) }; loginReq.send(params); } Can anyone help me? If you need more information, please contact me.Actual Result
The posttestserver answers every time: No Post Params. Empty post body.Expected Result
The posttestserver answers every time: No Post Params. Empty post body.Comments
- Mostafizur Rahman 2013-12-28
Hello,
I tested this issue with test code bellow. I can’t reproduce this issue in latest TiSDK 3.2GA. Please check my test code and let me know its working or not. If you have a different test case, please post a complete sample here.
Test Environment:
MAC OS X 10.8.5 TI SDK 3.2.0.GA Ti CLI 3.2.0 Alloy 1.3.0 IOS Simulator 7.0.3Test Code
Index.xml
index.js<Alloy> <Window id="todoWin" title="Todo" platform="android,ios"> <Button id="button" onClick="postData"> Post </Button> </Window> </Alloy>
Server Side code$.todoWin.open(); function postData() { var xhr = Ti.Network.createHTTPClient({ onload : function() { Ti.API.info("STATUS: " + this.status); alert("TEXT: " + this.responseText); //json = JSON.parse(this.responseText); }, onerror : function(e) { Ti.API.info("STATUS: " + this.status); Ti.API.info("TEXT: " + this.responseText); Ti.API.info("ERROR: " + e.error); alert(L('network_problem')); }, timeout : 50000 }); var data = { username : 'username', password : 'password' }; alert('data' + JSON.stringify(data)); xhr.open('POST', encodeURI('http://localhost/AppCTest/api.php')); xhr.setRequestHeader('Content-Type', 'application/json'); xhr.send(JSON.stringify(data)); }
<?php if ($_SERVER['REQUEST_METHOD'] == 'POST') { $params = file_get_contents('php://input'); $params = json_decode(str_replace('\"', '"', $params)); echo json_encode($params); } else { echo json_encode((object) array('error' => 'invalid verb')); }
Step to Test
Create alloy mobile apps
Update my code in index.xml and index.js file and also server side code
Click on post button its return post data from server
Thanks - Ritu Agrawal 2014-01-08 [~appcelerator@webdt.de] Please let us know if the provided test case helps solve your problem.
- Shak Hossain 2014-01-20 Marking this resolved since we can't reproduce the issue and the reporter has not provided us with any additional updates.