【发布时间】:2012-02-01 04:59:12
【问题描述】:
我正在尝试将 Java 应用程序转换为 C++,我正在使用 cURL 来处理我的请求。
下面是java代码;我想知道如何复制connection.setRequestProperty() 方法。
connection = (HttpURLConnection) url.openConnection();
connection.setInstanceFollowRedirects(false);
connection.setReadTimeout(10000);
String userId= =getUserId()
connection.setRequestProperty("UserID", userId);
以下是我当前不起作用的代码。
struct curl_slist *headers=NULL;
curl_slist_append(headers, "UserID="2");
curl_easy_setopt(curl,CURLOPT_HTTPHEADER,headers);
curl_easy_setopt(curl, CURLOPT_URL,url.c_str());
curl_easy_setopt(curl,CURLOPT_SSLVERSION, CURL_SSLVERSION_SSLv3);
curl_easy_setopt(curl, CURLOPT_CAINFO, certDataPath.c_str());
CURLcode c =curl_easy_setopt(curl, CURLOPT_WRITEFUNCTION, postRequestCallback);
以下是失败的 java servlet 代码(id 为 null 或空)
protected void doGet(HttpServletRequest request, HttpServletResponse response) throws
ServletException, IOException {
...
...
String ud = request.getHeader("UserID");
}
cURL 中setRequestProperty 的等效命令是什么。
我确定我遗漏了一些明显的东西。
【问题讨论】: