2

I am writing a client side code in Visual C++ 2012 using C++ Rest SDK (codename "Casablanca"). I have a client created and wish to POST a text string to the server. However, when I send the following code, it is compiling but not sending sending the request. When I remove everything after "methods::POST" and send a blank post request, then it is sent and received by the server. Can you please guide me where the problem is. The documentation related to this function is available on Casablanca Documentation.

pplx::task<http_response>resp = client.request(methods::POST,L"",L"This is the random text that I wish to send", L"text/plain");
Vaibhav
  • 158
  • 3
  • 8

4 Answers4

1

I think the usage you give here looks correct. Is your Casablanca the latest version ? Please check that out from here : http://casablanca.codeplex.com/ If you are sure your measurement is accurate, you may want to create a minimal repro and file a bug here : http://casablanca.codeplex.com/workitem/list/basic

Hong Hong
  • 11
  • 1
1

I was having a similar problem, all my POSTs was arriving in blank on server , after a few hours work above it, i found a possible solution. I changed the default content type to application/x-www-form-urlencoded and I started to pass the values like this Example data=text1&data2=text2

client.request(methods::POST,L"",L"data=text1&data2=text2", L"application/x-www-form-urlencoded");
Icaro Martins
  • 307
  • 12
  • 22
0

The body parameter must be a json::value.

Fabzter
  • 505
  • 5
  • 16
  • Can't a normal text be sent ? Also, when I try to create the json::value using -json::value obj; obj[L"key1"] = json::value::string(U("str")); The code hangs there itself only; it doesn't proceed further. I got this code from [link](http://blogs.msdn.com/b/vcblog/archive/2013/02/26/the-c-rest-sdk-quot-casablanca-quot.aspx) – Vaibhav Jun 15 '13 at 07:06
0

I cannot comment yet so I have to put my thoughts in an answer. I solved this problem like this: There is an overload of the request method that takes as a parameter the content type so that you do not have to change the code.

m_client->request(methods::POST, L"/statuses/update.json?" + url_encode(data),L"",L"application/x-www-form-urlencoded");

Obviously you would have to implement the url_encode method but that is not difficult. There is a pretty good implementation in "Cassablanca". A search on this site will alos turn up some good examples.

James Pack
  • 824
  • 1
  • 10
  • 19