Send json data in http post request

Hi,

i have two string variable username and password which has value taken from user and want to send data to server for authentication.

HttpRequest* request = new HttpRequest();
request->setUrl("http://server/login.php");
request->setRequestType(HttpRequest::Type::POST);
std::vector<std::string> headers;
headers.push_back("Content-Type: application/json; charset=utf-8");
request->setHeaders(headers);
request->setResponseCallback(CC_CALLBACK_2(HelloWorld::onHttpRequestCompleted, this));

// write the post data

std::string postData = "id=mihir&pass=thkr";
request->setRequestData(postData.c_str(), postData.length());
request->setTag("POST test2");
HttpClient::getInstance()->send(request);
request->release();

The request return :

 POST test2 completed
 response code: 200

But no data is echoed on server…plz help…

my php code is:(tried every possible way to get data):

<?php

$postdata = file_get_contents('php://input');
echo $postdata;
$input= json_decode( $postdata, TRUE );
echo $input;

$obj = json_decode($json);
echo $obj;

$name = $_POST['id'];
$score = $_POST['pass'];

echo $name;
echo $score;

?>

Anyone plz…Whats wrong with the code.

Hi, were you able to solve this issue?

@slackmoehrle please help this guy.no one reply him after 6 month,cocos2dx support team should address developer issue carefully.

I don’t even know if he is having the problem still and what version of Cocos2d-x he was/is using.

Hi guys, i solved this issue few days after posting. Thanks for noticing…

1 Like

can you share your solution here .
thanks in advance…

what do you need @shaktiraj ? let me know ,how can i help you

i want to send my plist file to php server.

you can send it through Json, please share your email id i will send you code sample.