Click here to Skip to main content
15,881,803 members
Please Sign up or sign in to vote.
1.00/5 (3 votes)
Hi i want to make simple request response program in vc++. which is like on my localhost at helloworld.jsp there is output hello world when i send request to hellowworld.jsp it should give me output hello world. i try couple of things but it is also working but it gives me output of whole webpage of helloworld.jsp

C++
#include "stdafx.h"
#include <stdio.h>
#include "curl/curl.h"

int main(void)
{
  CURL *curl;
  CURLcode res;

  /* In windows, this will init the winsock stuff */ 
  curl_global_init(CURL_GLOBAL_ALL);

  /* get a curl handle */ 
  curl = curl_easy_init();
  if(curl) {
    /* First set the URL that is about to receive our POST. This URL can
       just as well be a https:// URL if that is what should receive the
       data. */ 
    curl_easy_setopt(curl, CURLOPT_URL, "http://localhost:8080/asigra_1/helloword.jsp");
    /* Now specify the POST data */ 
    curl_easy_setopt(curl, CURLOPT_POSTFIELDS, "name=daniel&project=curl");

    /* Perform the request, res will get the return code */ 
    res = curl_easy_perform(curl);
    /* Check for errors */ 
    if(res != CURLE_OK)
      fprintf(stderr, "curl_easy_perform() failed: %s\n",
              curl_easy_strerror(res));

    /* always cleanup */ 
    curl_easy_cleanup(curl);
  }
  curl_global_cleanup();
  system("pause");
  return 0;

}



i get following output for it
XML
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.or
g/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
<title>Insert title here</title>
</head>
<body>
hello word

</body>
</html>Press any key to continue . . .




how should i get output only in one line which is like hello world.
Posted
Updated 28-Apr-14 0:05am
v2
Comments
Jochen Arndt 28-Apr-14 5:12am    
That is how HTTP works. If you want only the content you must use some kind of HTML parser that produces plain text. With your simple example it would be enough to strip out the text between the BODY start and end tag. If the body contains other HTML tags, you may remove or process them and finally convert HTML entities to their text representations.
Member 10678759 28-Apr-14 5:45am    
ok sir thank you..i at least send request..would you tell me how jsp server acknowledge my request now?
pasztorpisti 28-Apr-14 6:50am    
If you want to get just pure "Hello World!" then you don't have to send html from the server, simple text/plain would do the job and for that you don't need templating engines like jsp.
Member 10678759 28-Apr-14 9:07am    
i want string which is there on server..right now string on server is hello world

1 solution

The best solution is use an HTML parser in client side so you can filter out the message. If it is complex you can simply wrap your message with a tag which is not used in HTML. Check the following example,
XML
<body>
<message>hello word</message>

now you can find for the content within the <message></message> tags with string manipulation techniques in c++. If you like you can use regular expressions too.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900