我正在使用libcurl发送http消息。
我开发了以下函数,其中我启动curl选项,然后执行http消息的发送。以下代码中未激活选项CURLOPT_VERBOSE
。但是在执行以下功能时,收到的http消息会显示在详细信息中。我该如何解决这个问题?
http_lightweight_notification(char *msg_out, int msg_out_len)
{
static CURL *n_curl;
CURLcode res;
struct curl_slist *chunk = NULL;
char *url="http://192.168.1.133:8080";
char buf[SIGNATURE_LEN + sizeof("Signature: ")] = "Signature: ";
char *signature = buf + sizeof("Signature: ") - 1;
if (!msg_out) return -1;
n_curl = curl_easy_init();
if (!n_curl) return -1;
signature_hmac_sha1(msg_out, "anykey", signature);
chunk = curl_slist_append(chunk, "Content-Type: text/xml; charset=utf-8");
if (!chunk) return -1;
chunk = curl_slist_append(chunk, "Accept:");
if (!chunk) return -1;
chunk = curl_slist_append(chunk, buf);
if (!chunk) return -1;
curl_easy_setopt(n_curl, CURLOPT_URL, url);
curl_easy_setopt(n_curl, CURLOPT_HTTPHEADER, chunk);
curl_easy_setopt(n_curl, CURLOPT_TIMEOUT, 30);
curl_easy_setopt(n_curl, CURLOPT_CONNECTTIMEOUT, 30);
curl_easy_setopt(n_curl, CURLOPT_POSTFIELDS, msg_out);
curl_easy_setopt(n_curl, CURLOPT_POSTFIELDSIZE, (long) msg_out_len);
# if 0
curl_easy_setopt(n_curl, CURLOPT_VERBOSE, 1L);
# endif
res = curl_easy_perform(n_curl);
if (chunk) {
curl_slist_free_all(chunk);
chunk = NULL;
}
curl_easy_cleanup(n_curl);
curl_global_cleanup();
if (res) return -1;
return 0;
}
详细输出是:
<html><head><title>JBossWeb/2.0.1.GA - Rapport d'erreur</title><style><!--H1 {font-family:Tahoma,Arial,sans-serif;color:white;background-color:#525D76;font-size:22px;} H2 {font-family:Tahoma,Arial,sans-serif;color:white;background-color:#525D76;font-size:16px;} H3 {font-family:Tahoma,Arial,sans-serif;color:white;background-color:#525D76;font-size:14px;} BODY {font-family:Tahoma,Arial,sans-serif;color:black;background-color:white;} B {font-family:Tahoma,Arial,sans-serif;color:white;background-color:#525D76;} P {font-family:Tahoma,Arial,sans-serif;background:white;color:black;font-size:12px;}A {color : black;}A.name {color : black;}HR {color : #525D76;}--></style> </head><body><h1>Etat HTTP 500 - </h1><HR size="1" noshade="noshade"><p><b>type</b> Rapport d'exception</p><p><b>message</b> <u></u></p><p><b>description</b> <u>Le serveur a rencontrأ� une erreur interne () qui l'a empأ�chأ� de satisfaire la requأ�te.</u></p><p><b>exception</b> <pre>org.jboss.ws.core.CommonSOAPFaultException: org.xml.sax.SAXParseException: Content is not allowed in prolog.
org.jboss.ws.core.soap.EnvelopeBuilderDOM.build(EnvelopeBuilderDOM.java:93)
org.jboss.ws.core.soap.MessageFactoryImpl.createMessage(MessageFactoryImpl.java:262)
org.jboss.ws.core.soap.MessageFactoryImpl.createMessage(MessageFactoryImpl.java:185)
org.openacs.ACSServlet.processRequest(ACSServlet.java:331)
org.openacs.ACSServlet.doPost(ACSServlet.java:588)
javax.servlet.http.HttpServlet.service(HttpServlet.java:710)
javax.servlet.http.HttpServlet.service(HttpServlet.java:803)
org.jboss.web.tomcat.filters.ReplyHeaderFilter.doFilter(ReplyHeaderFilter.java:96)
</pre></p><p><b>note</b> <u>La trace complأ�te de la cause mأ�re de cette erreur est disponible dans les fichiers journaux de JBossWeb/2.0.1.GA.</u></p><HR size="1" noshade="noshade"><h3>JBossWeb/2.0.1.GA</h3></body></html>
答案 0 :(得分:1)
这不是详细的输出,而是您收到的内容的正文。
通过将CURLOPT_WRITEFUNCTION设置为接收数据,或者可能将CURLOPT_WRITEDATA设置为不同的FILE *句柄,禁止将内容发送到stdout(这是默认设置)。
显示在getinmemory.c示例中。