Urgent, how to obtain the HTTP response JSON by C language?

Hello everyone, I'm new to JSON, the current situation is this.

The current through the socket I can access to the server to my HTTP 200 response.

If the char (string) for less than JSON, how should I do, can convert the JSON data I want?

Thank you. Please give advice.

"Get response: _____HTTP/1.1 200 OK
Server: nginx/1.2.9
Date: Tue, 12 Nov 2013 02:43:17 GMT
Content-Type: application/json
Content-Length: 695
Connection: close
Cache-Control: no-store, no-cache, must-revalidate, post-check=0, pre-check=0
Expires: Thu, 19 Nov 1981 08:52:00 GMT
Pragma: no-cache
Set-Cookie: PHPSESSID=6ck0seh2pm1bri6a3une13d0; expires=Tue, 12-Nov-2013 04:43:16 GMT; path=/; domain=.testjason.com
Set-Cookie: PHPSESSID=7jcnpib7jqtn3hvik5lr07; expires=Tue, 12-Nov-2013 04:43:16 GMT; path=/; domain=.testjason.com
Vary: Accept-Encoding,User-Agent
X-Powered-By: PHP/5.4.17
Front-End-Https: on
Set-Cookie: incap_ses_120_88065=Ml3qRB0y9A1+OC6t0VOqAcSVgVIAAAxv9Ro078RVpr6+9lTtv5/w==; path=/; Domain=.testjason.com
Set-Cookie: visid_incap_88065=lLvLqEcJSgm5afxKrEVvF8SVgVIAAAAAQUIAAAAAAC9MGYZUu7nrI+iyDpz7Iq; expires=Wed, 11 Nov 2015 13:12:45 GMT; path=/; Domain=.testjason.com
X-Iinfo: 6-7457662-74577747 NNN CT(170 170 0) RT(13842195263 405) q(0 0 4 -1) r(4 6) U6
X-CDN: Incapsula


Started by Abelard at February 14, 2016 - 11:35 PM

The code is sent to all work together to see you?

Posted by Morton at January 01, 2017 - 10:12 PM

The code should say is very simple.

180 int socket = 0;
181 SSL* sslHandle = NULL;
182 SSL_CTX* sslContext = NULL;
183 if (SslConnect("testjson.com", 443, socket, sslHandle, sslContext)) {
184 SSL_write(sslHandle, postContent.c_str(), postContent.size());
185 string response = ReadAllFromSSL(sslHandle);
186 cout <<"Get response: _____" <<response <<"____" <<endl;
187 }
189 // Cleanups no matter connect succeed or not.
190 if (socket != 0) {
191 close(socket);
192 }
193 if (sslHandle) {
194 SSL_shutdown(sslHandle);
195 SSL_free(sslHandle);
196 }
197 if (sslContext) {
198 SSL_CTX_free(sslContext);
199 }
200 return 0;
201 }

Posted by Abelard at January 05, 2017 - 11:16 PM

Now all the data that HTTP reponse is stored in a char *buffer. I just don't know how to extract from the buffer to the JSON data.

After all, HTTP protocol also has the format.?

Posted by Abelard at January 13, 2017 - 11:24 PM

There is a problem, your code is testjson.com, the returned data is more like a return to head a normal URL request, are you sure that URL will be returned to you on the head inside JSON format data?
At least, I found the information is: there are three kinds of JSON data acquisition method:
Use only HTTP Headers
Use HTTP Headers + json body
Always use json and add at the root of the response a boolean responseValid and a error object

Posted by Morton at January 14, 2017 - 10:25 PM

To find the actual data back.:
User-Agent: Mozilla/5.0 (X11; Ubuntu; Linux i686; rv:10.0.2) Gecko/20100101 Firefox/10.0.2
Accept: text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8
Accept-Language: eo,de-de;q=0.8,de;q=0.6,en-us;q=0.4,en;q=0.2
Accept-Encoding: gzip, deflate
Connection: keep-alive
Content-Type: application/json; charset=utf-8
Referer: http://localhost/form.html
Content-Length: 88
Cookie: {{..to much data..}}
Pragma: no-cache
Cache-Control: no-cache
The last line should be JSON data.
At the same time, in the Q& A inside, someone mentioned, if the call to JSON if there is no point to an offer you data calls, there may be no results.
So, you can try to change under the URL.

Posted by Morton at January 14, 2017 - 10:49 PM