{"action":"created","issue":{"url":"https://api.github.com/repos/Microsoft/cpprestsdk/issues/100","repository_url":"https://api.github.com/repos/Microsoft/cpprestsdk","labels_url":"https://api.github.com/repos/Microsoft/cpprestsdk/issues/100/labels{/name}","comments_url":"https://api.github.com/repos/Microsoft/cpprestsdk/issues/100/comments","events_url":"https://api.github.com/repos/Microsoft/cpprestsdk/issues/100/events","html_url":"https://github.com/Microsoft/cpprestsdk/issues/100","id":142103904,"number":100,"title":"1 request, 2 responses?","user":{"login":"Kitof","id":199109,"avatar_url":"https://avatars.githubusercontent.com/u/199109?v=3","gravatar_id":"","url":"https://api.github.com/users/Kitof","html_url":"https://github.com/Kitof","followers_url":"https://api.github.com/users/Kitof/followers","following_url":"https://api.github.com/users/Kitof/following{/other_user}","gists_url":"https://api.github.com/users/Kitof/gists{/gist_id}","starred_url":"https://api.github.com/users/Kitof/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/Kitof/subscriptions","organizations_url":"https://api.github.com/users/Kitof/orgs","repos_url":"https://api.github.com/users/Kitof/repos","events_url":"https://api.github.com/users/Kitof/events{/privacy}","received_events_url":"https://api.github.com/users/Kitof/received_events","type":"User","site_admin":false},"labels":[],"state":"closed","locked":false,"assignee":null,"milestone":null,"comments":0,"created_at":"2016-03-19T21:51:58Z","updated_at":"2016-03-20T22:46:16Z","closed_at":"2016-03-20T22:46:16Z","body":"I use C++ REST SDK Casablanca in a Rainmeter plugin.\r\n\r\nI make a POST request to a REST API, but the response part of code seems to be execute twice according to the debug log.\r\n\r\nIn the code below, Initialize() is called by the Rainmeter application.\r\n\r\n```cpp\r\n    struct FbxAuth_t\r\n    {\r\n    \tstd::wstring status;\r\n    \tstd::wstring challenge;\r\n    \tstd::wstring password_salt;\r\n    \tstd::wstring app_token;\r\n    \tstd::wstring track_id;\r\n    };\r\n    \r\n    FbxAuth_t fbxAuth;\r\n    \r\n    void DisplayJSONValue(json::value v)\r\n    {\r\n    \tRmLog(LOG_DEBUG, L\"DisplayJSONValue\");\r\n    \tif (!v.is_null())\r\n    \t{\r\n    \t\t// Loop over each element in the object\r\n    \t\tfor (auto iter = v.as_object().cbegin(); iter != v.as_object().cend(); ++iter)\r\n    \t\t{\r\n    \t\t\t// It is necessary to make sure that you get the value as const reference\r\n    \t\t\t// in order to avoid copying the whole JSON value recursively (too expensive for nested objects)\r\n    \t\t\tauto key = iter->first;\r\n    \t\t\tstd::wstring wkey = conversions::to_utf16string(key);\r\n    \t\t\tauto& value = iter->second;\r\n    \r\n    \t\t\tRmLog(LOG_DEBUG, buffer);\r\n    \t\t\tif (value.is_object() || value.is_array())\r\n    \t\t\t{\r\n    \t\t\t\t// We have an object with children or an array\r\n    \r\n    \t\t\t\t_snwprintf_s(buffer, _TRUNCATE, L\"Parent: %s\", wkey.c_str());\r\n    \t\t\t\tRmLog(LOG_DEBUG, buffer);\r\n    \t\t\t\t// Loop over each element in the object by calling DisplayJSONValue\r\n    \t\t\t\tDisplayJSONValue(value);\r\n    \t\t\t\t_snwprintf_s(buffer, _TRUNCATE, L\"End of Parent: %s\", wkey.c_str());\r\n    \t\t\t\tRmLog(LOG_DEBUG, buffer);\r\n    \t\t\t}\r\n    \t\t\telse\r\n    \t\t\t{\r\n    \t\t\t\tstd::wstring wvalue = conversions::to_utf16string(value.serialize());\r\n    \t\t\t\t// Always display the value as a string\r\n    \t\t\t\t_snwprintf_s(buffer, _TRUNCATE, L\"Key: %s Value: %s\", wkey.c_str(), wvalue.c_str());\r\n    \t\t\t\tRmLog(LOG_DEBUG, buffer);\r\n    \t\t\t}\r\n    \t\t}\r\n    \t}\r\n    }\r\n    \r\n    pplx::task<bool> FBXRegister()\r\n    {\r\n    \tRmLog(LOG_DEBUG, L\"FBXRegister\");\r\n    \tjson::value query;\r\n    \tquery[L\"app_id\"] = json::value::string(L\"net.rainmeter.plugin.rainfbx\");\r\n    \tquery[L\"app_name\"] = json::value::string(L\"Rainmeter Freebox Plugin\");\r\n    \tquery[L\"app_version\"] = json::value::string(L\"0.0.1\");\r\n    \tquery[L\"device_name\"] = json::value::string(L\"KitFixe\");\r\n    \r\n    \thttp_client client(L\"http://mafreebox.freebox.fr/\");\r\n    \treturn client.request(methods::POST, L\"/api/v3/login/authorize/\", conversions::to_utf16string(query.serialize()), L\"application/json\").then([](http_response response) -> pplx::task<json::value>\r\n    \t{\r\n    \t\tif (response.status_code() == status_codes::OK)\r\n    \t\t{\r\n    \t\t\treturn response.extract_json();\r\n    \t\t}\r\n    \r\n    \t\t// Handle error cases, for now return empty json value...\r\n    \t\treturn pplx::task_from_result(json::value());\r\n    \t})\r\n    \t\t.then([](pplx::task<json::value> previousTask)\r\n    \t{\r\n    \r\n    \t\tconst json::value& v = previousTask.get();\r\n    \r\n    \t\tDisplayJSONValue(v);\r\n    \r\n    \t\tif(_wcsicmp(v.at(L\"success\").serialize().c_str(), L\"true\") == 0) {\r\n    \t\t\tfbxAuth.track_id = v.at(L\"result\").at(L\"track_id\").serialize();\r\n    \t\t\tfbxAuth.app_token = v.at(L\"result\").at(L\"app_token\").serialize();\r\n    \t\t\treturn true;\r\n    \t\t}\r\n    \t\treturn false;\r\n    \t});\r\n    }\r\n    \r\n    PLUGIN_EXPORT void Initialize(void** data, void* rm)\r\n    {\r\n    \tRmLog(LOG_DEBUG, L\"Initialize\");\r\n    \tMeasureData* measure = new MeasureData;\r\n    \t*data = measure;\r\n    \tfbxAuth.app_token = RmReadString(rm, L\"FbxAppToken\", L\"\");\r\n    \r\n    \tif(_wcsicmp(fbxAuth.app_token.c_str(), L\"\") == 0)\r\n    \t{\r\n    \t\tFBXRegister();\r\n    \t}\r\n    }\r\n```\r\n\r\nDebug log is filled by RmLog calls.\r\n\r\nHere is the result :\r\n\r\n    DBUG (16:28:11.999) : Initialize\r\n    DBUG (16:28:12.006) : FBXRegister\r\n    DBUG (16:28:13.901) : DisplayJSONValue\r\n    DBUG (16:28:13.912) : \r\n    DBUG (16:28:13.923) : Parent: result\r\n    DBUG (16:28:13.934) : DisplayJSONValue\r\n    DBUG (16:28:13.943) : Parent: result\r\n    DBUG (16:28:13.952) : Key: app_token Value: \"WL<snip>vecn\"\r\n    DBUG (16:28:13.958) : Key: app_token Value: \"WL<snip>vecn\"\r\n    DBUG (16:28:13.964) : Key: track_id Value: 104\r\n    DBUG (16:28:13.971) : End of Parent: result\r\n    DBUG (16:28:13.977) : End of Parent: result\r\n    DBUG (16:28:13.983) : Key: success Value: true\r\n\r\nIt's seems that DisplayJSONValue is called twice, but the first response seems incomplete. How to avoid this ?\r\n\r\nI'm not familiar with task, maybe this is the problem ?\r\n\r\nThanks a lot for your help !"},"comment":{"url":"https://api.github.com/repos/Microsoft/cpprestsdk/issues/comments/199054009","html_url":"https://github.com/Microsoft/cpprestsdk/issues/100#issuecomment-199054009","issue_url":"https://api.github.com/repos/Microsoft/cpprestsdk/issues/100","id":199054009,"user":{"login":"Kitof","id":199109,"avatar_url":"https://avatars.githubusercontent.com/u/199109?v=3","gravatar_id":"","url":"https://api.github.com/users/Kitof","html_url":"https://github.com/Kitof","followers_url":"https://api.github.com/users/Kitof/followers","following_url":"https://api.github.com/users/Kitof/following{/other_user}","gists_url":"https://api.github.com/users/Kitof/gists{/gist_id}","starred_url":"https://api.github.com/users/Kitof/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/Kitof/subscriptions","organizations_url":"https://api.github.com/users/Kitof/orgs","repos_url":"https://api.github.com/users/Kitof/repos","events_url":"https://api.github.com/users/Kitof/events{/privacy}","received_events_url":"https://api.github.com/users/Kitof/received_events","type":"User","site_admin":false},"created_at":"2016-03-20T22:46:16Z","updated_at":"2016-03-20T22:46:16Z","body":"Nevermind. I found the bug in my code. Sorry ;)"}}