[英]Converting from java to c++, what is the equivalent curl command for setRequestProperty
I'm trying to convert a Java application to C++, I am using cURL for my requests. 我正在尝试将Java应用程序转换为C ++,我正在使用cURL来处理我的请求。 Below is the java code;
下面是java代码; I'm wondering how to replicate the
connection.setRequestProperty()
method. 我想知道如何复制
connection.setRequestProperty()
方法。
connection = (HttpURLConnection) url.openConnection();
connection.setInstanceFollowRedirects(false);
connection.setReadTimeout(10000);
String userId= =getUserId()
connection.setRequestProperty("UserID", userId);
Below is my current code that does not work. 以下是我当前的代码不起作用。
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);
Below is a the java servlet code that is failing (id is null or empty) 下面是一个失败的java servlet代码(id为null或为空)
protected void doGet(HttpServletRequest request, HttpServletResponse response) throws
ServletException, IOException {
...
...
String ud = request.getHeader("UserID");
}
What is the equiv command to setRequestProperty
in cURL. 在cURL中
setRequestProperty
的equiv命令是什么。
I'm sure I am missing something obvious. 我确定我错过了一些明显的东西。
Might be your header string format is off, how about: 你的标题字符串格式可能会关闭,怎么样:
curl_slist_append(headers, "UserID: 2"); curl_slist_append(headers,“UserID:2”);
ah, you need to assign the result, so 啊,你需要分配结果,所以
headers = curl_slist_append(headers, "UserID: 2"); headers = curl_slist_append(headers,“UserID:2”);
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.