Question
I'm developing a Tizen native application where the HTTP POST method was working correctly before upgrading to Tizen Studio 2.0. After the upgrade, while the connection to the server is established, I'm not getting the expected output despite providing correct parameters.
The same API and parameters work properly in REST clients, and the code was functioning correctly with Tizen Studio 1.3. Can anyone help identify what might be causing this issue?
Answer
Problem Understanding
The issue appears to be related to HTTP POST functionality in native applications after upgrading to Tizen Studio 2.0. While the connection is established, the expected response isn't received, despite the same code working in previous versions and in REST clients.
Solution Methods
-
Verify Target Environment:
- Check if you're testing on the same device/emulator as before
- Try with different emulator versions or real devices
-
Code Review:
- Ensure all HTTP transaction callbacks are properly registered
- Verify the request format matches server expectations
-
Content-Type Header:
- Explicitly set the Content-Type header for your POST request
- For JSON data, use:
http_transaction_request_set_header(transaction, "Content-Type", "application/json")
Code Examples
int ret = HTTP_ERROR_NONE;
char uri[1024] = "http://posttestserver.com/post.php";
const char* post_msg = "name=tizen&project=http";
ret = http_session_create(HTTP_SESSION_MODE_NORMAL, &session);
if (ret != HTTP_ERROR_NONE)
dlog_print(DLOG_DEBUG, "my_tag","http_session_create failed: %d", ret);
// Set Content-Type header for JSON data
ret = http_transaction_request_set_header(transaction, "Content-Type", "application/json");
if (ret != HTTP_ERROR_NONE)
dlog_print(DLOG_DEBUG, "my_tag","Failed to set header: %d", ret);
ret = http_session_open_transaction(session, HTTP_METHOD_POST, &transaction);
if (ret != HTTP_ERROR_NONE)
dlog_print(DLOG_DEBUG, "my_tag","http_session_open_transaction failed: %d", ret);
ret = http_transaction_request_set_uri(transaction, uri);
if (ret != HTTP_ERROR_NONE)
dlog_print(DLOG_DEBUG, "my_tag","http_transaction_request_set_uri failed: %d", ret);
http_transaction_set_ready_to_write(transaction, TRUE);
http_transaction_request_write_body(transaction, post_msg);
ret = http_transaction_submit(transaction);
if (ret != HTTP_ERROR_NONE)
dlog_print(DLOG_DEBUG, "my_tag","http_transaction_submit failed: %d", ret);
Additional Tips
- Check the server logs for any errors or malformed requests
- Verify network permissions in your manifest file
- Test with different Content-Type headers (application/x-www-form-urlencoded for form data)
- Consider using curl or Postman to verify the API independently