我正在尝试将 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 为空或空)
protected void doGet(HttpServletRequest request, HttpServletResponse response) throws
ServletException, IOException {
...
...
String ud = request.getHeader("UserID");
}
setRequestProperty
cURL 中的等效命令是什么。
我确定我遗漏了一些明显的东西。