언어 설정

Menu
Sites
Language
after installation tizen studio 2.0 http post method is not working properly for native application.

Hello, 

 

I am working on tizen native application. http post method was working before the installation of tizen studio 2.0 

 

Now i have installed tizen studio 2.0 so now my http post method is not working properly. 

 

it is connecting to te server. but still i am not getting the output. 

Though i have given correct parameters, am not getting the expected results. 

and the same api n parameters are working properly in rest cllient also. 

and the same code was working fine with tizen studio 1.,3. 

can anyone help me on this?

 

Responses

8 댓글
Armaan-Ul- Islam

Tizen Studio 2.0 Release Notes don't contain any notice regerding http POST request.

https://developer.tizen.org/development/tizen-studio/download/release-notes

 

An IDE update won't make changes in API. What was the target device on your test environment before? Was it the same Mobile-3.0x86 emulator? Or any other version of Emulator or a real device? I would suggest to try with a different emulator or device first.

Mick Caberos

Hi Supreeth Kumar can you share some sample code of HTTP post? i also dont know how to use the code snippet from there website . please thanks in andvance

Armaan-Ul- Islam

I'm sharing sample code for HTTP POST request. Hope It helps.

 

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);

//Transaction for HTTP POST:
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);

//Data management for HTTP POST:
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);

header_cb(http_transaction_h http_transaction, char *header, size_t header_len, void *user_data){
    // response received header here (char *header)
}

body_cb(http_transaction_h http_transaction, char *body, size_t size, size_t count, void *user_data){
    // response received body here (char *body)
}

// Registers callback called when receives header. 
http_transaction_set_received_header_cb (transaction, header_cb, null);
http_transaction_set_received_body_cb (transaction,body_cb, null);

 

Check these Documentations for details:

HTTP transaction API References

HTTP API References

HTTP Response API References

Mick Caberos

Armaan-Ul- Islam actually we have the same code but mine is not working. i have a question do i have to change the format of post_msg to JSON format?

 

const char* post_msg = "name=tizen&project=http";
Mick Caberos
hi i have a follow up question. my goal is to get the value "userId: 1" "id:2" what will be the format of post_msg? thanks


[
  {
    "userId": 1,
    "id": 1,
    "title": "sunt aut facere repellat provident occaecati excepturi optio reprehenderit",
    "body": "quia et suscipit\nsuscipit recusandae consequuntur expedita et cum\nreprehenderit molestiae ut ut quas totam\nnostrum rerum est autem sunt rem eveniet architecto"
  },
  {
    "userId": 1,
    "id": 2,
    "title": "qui est esse",
    "body": "est rerum tempore vitae\nsequi sint nihil reprehenderit dolor beatae ea dolores neque\nfugiat blanditiis voluptate porro vel nihil molestiae ut reiciendis\nqui aperiam non debitis possimus qui neque nisi nulla"
  },
Armaan-Ul- Islam

As far as I've understood, Your post message should be like:

const char* post_msg = "userId=1&id=2";

 

 Relevant articles you might like to check:

https://stackoverflow.com/questions/14551194/how-are-parameters-sent-in-an-http-post-request

https://developer.mozilla.org/en-US/docs/Web/HTTP/Methods/POST

Mick Caberos
 
Hi btw merry christmas haha. this is my code please see below. but i cant receive data body of http post? hmm the parameter that need to send to server is JSON format. but if i set it like this format const char* post_msg = "title=mick&body=helloworld" will the server accept it? because i keep trying it over and over again with the right variables but it fails and just returning nothing and when i tried different server the return is 404 not found
 
void body_cb(http_transaction_h transaction, char* body, size_t size, size_t nmemb, void* user_data) {
dlog_print(DLOG_INFO, LOG_TAG, "session body = %s", body);
dlog_print(DLOG_INFO, LOG_TAG, "session size = %d", size);
dlog_print(DLOG_INFO, LOG_TAG, "session nmemb = %d", nmemb);
dlog_print(DLOG_INFO, LOG_TAG, "session body = %s", transaction);
}
void header_cb(http_transaction_h transaction, char* header, size_t header_len, void* user_data) {
//appdata_s *ad = data;
dlog_print(DLOG_INFO, LOG_TAG, "session pangalawa", NULL);
dlog_print(DLOG_INFO, LOG_TAG, "session HEADER = %s", header);
dlog_print(DLOG_INFO, LOG_TAG, "session len = %d", header_len);
dlog_print(DLOG_INFO, LOG_TAG, "session body = %s", transaction);
 
{
 
 
static void _onButtonClickedCb(void *data, Evas_Object *obj, void *event_info)
{
appdata_s *ad = data;
int ret = HTTP_ERROR_NONE;
http_session_h session = NULL;
http_transaction_h transaction = NULL;
bool auto_redirect = true;
http_method_e method = HTTP_METHOD_GET;
http_status_code_e status_code = -1;
http_version_e version = -1;
bool jaraba = true;
 
 
char uri[1024] = "https://jsonplaceholder.typicode.com/posts";
const char* post_msg = "title=mick&body=helloworld"
 
ret = http_init();
if (ret != HTTP_ERROR_NONE){
dlog_print(DLOG_INFO, LOG_TAG, "session http_init failed = %d", ret);
}else {
dlog_print(DLOG_INFO, LOG_TAG, "session http_init success = %d", ret);
}
 
 
ret = http_session_create(HTTP_SESSION_MODE_NORMAL, &session);
if (ret != HTTP_ERROR_NONE){
dlog_print(DLOG_INFO, LOG_TAG, "session failed = %d", ret);
}else {
dlog_print(DLOG_INFO, LOG_TAG, "session create success = %d", ret);
}
 
ret = http_session_set_auto_redirection(session, auto_redirect);
if (ret != HTTP_ERROR_NONE){
    dlog_print(DLOG_INFO, LOG_TAG, "session http_session_set_auto_redirection failed = %d", ret);
}else {
dlog_print(DLOG_INFO, LOG_TAG, "session http_session_set_auto_redirection success = %d", ret);
}
 
ret = http_session_open_transaction(session, HTTP_METHOD_POST, &transaction);
if (ret != HTTP_ERROR_NONE){
dlog_print(DLOG_INFO, LOG_TAG, "session http_session_open_transaction failed = %d", ret);
}else {
dlog_print(DLOG_INFO, LOG_TAG, "session http_session_open_transaction success = %d", ret);
}
 
ret = http_transaction_request_set_uri(transaction, uri);
if (ret != HTTP_ERROR_NONE){
dlog_print(DLOG_INFO, LOG_TAG, "session http_transaction_request_set_uri failed = %d", ret);
}else{
dlog_print(DLOG_INFO, LOG_TAG, "session http_transaction_request_set_uri success = %d", ret);
}
 
 
ret = http_transaction_request_set_method(transaction, method);
if (ret != HTTP_ERROR_NONE){
dlog_print(DLOG_INFO, LOG_TAG, "session http_transaction_request_set_method failed = %d", ret);
}else{
dlog_print(DLOG_INFO, LOG_TAG, "session http_transaction_request_set_method success = %d", ret);
}
 
   http_transaction_set_ready_to_write(transaction, jaraba);
   http_transaction_request_write_body(transaction, post_msg);
 
ret = http_transaction_submit(transaction);
if (ret != HTTP_ERROR_NONE){
    dlog_print(DLOG_INFO, LOG_TAG, "session http_transaction_submit failed = %d", ret);
}else{
    dlog_print(DLOG_INFO, LOG_TAG, "session http_transaction_submit success = %d", ret);
}
 
http_transaction_set_received_header_cb(transaction, header_cb, NULL);
http_transaction_set_received_body_cb(transaction, body_cb, NULL);
}
 
 
 
 
 
 
 
 
 
}
Armaan-Ul- Islam

It's pretty common that Servers send HTTP response in JSON format, but Servers receiving HTTP Request in JSON format seems not that commonly followed standard.

 

May check this post on Stack Overflow:

https://stackoverflow.com/questions/7181534/http-post-using-json-in-java

According to the post, You might give this a try:

const char* post_msg = "data={\"userId\":\"1\",\"id\":\"2\"}";