如何在vc ++中编写简单的请求响应程序 [英] how to write simple request response program in vc++

查看:98
本文介绍了如何在vc ++中编写简单的请求响应程序的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

您好我想在vc ++中制作简单的请求响应程序。这就像我在helloworld.jsp上的localhost那样输出hello world当我向hellowworld.jsp发送请求它应该给我输出hello world。我尝试了几件事,但它也有效,但它给了我helloworld.jsp整个网页的输出



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

#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得到以下输出




i get following output for it

<!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 . . .









我应该如何才能获得输出在一行中就像hello world。





how should i get output only in one line which is like hello world.

推荐答案

最好的解决方案是在客户端使用HTML解析器,以便过滤掉消息。如果它很复杂,您只需使用HTML中未使用的标记包装您的消息即可。检查以下示例,

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,
<body>
<message>hello word</message>



现在您可以找到内的内容;消息>< / message> 在c ++中使用字符串操作技术的标记。如果您愿意,也可以使用正则表达式。


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.


这篇关于如何在vc ++中编写简单的请求响应程序的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆