- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我正在尝试将 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
的等效命令是什么。
我确定我遗漏了一些明显的东西。
最佳答案
可能是你的标题字符串格式不对,怎么样:
curl_slist_append(headers, "UserID: 2");
啊,你需要给结果赋值,所以
headers = curl_slist_append(headers, "UserID: 2");
关于java - 从 java 转换为 c++,setRequestProperty 的等效 curl 命令是什么,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8707440/
尝试使用具有暂停/恢复功能的“输入/输出流”进行下载。问题是当我将requestproperty设置为我下载的数量时:connection.setRequestProperty(“Range”,“by
我正在开发一个 Android 应用程序来研究 URLConnection 的使用并获取 JSON 格式的数据。 我发现了许多很好的资源和如何编码的示例 在哪里可以找到所有有效 RequestProp
我正在编写一个 HTTP 客户端,它需要解析来自网络服务器的响应,并且我遇到了(另一个)问题。 我发现有一个页面我被重定向到他们的移动内容门户:示例:www.example.com/m/public。
我在Android中实现POST请求,上传图片到服务成功。 我没有使用setRequestProperty函数;但是我想知道这个函数的作用是什么。 这是代码: URL url = new URL("h
我正在使用 httpurlconnection 类,现在我转向 volley 如何放置授权 token HttpURLConnection connection = (HttpURLConnecti
假设我正在与网络服务器进行 HTTP 通信,我将接受 html 或文本,但更喜欢 html。换句话说,标题应该说(我认为!) 接受:text/html, text/* 我使用的是 Java,所以我有一
我正在尝试用 Java 发出 get 请求。但是,当我运行这段代码时, URL urlForGetRequest = new URL("my_url"); String readLine = nu
URL url = new URL("http://www.example.com/comment"); HttpURLConnection connection = (HttpURLConnecti
我有一个 Android 应用程序需要在连接中设置请求属性。这是我的代码: URL url = new URL(sUrl); HttpURLConnection connection = (Htt
我正在努力将授权 token 设置为 Alamofire Swift 中的连接请求属性。 我尝试在 header 中发送身份验证 token 并能够实现这一目标。 在android中,我们将身份验证
HTTPConnection连接方法 设置请求属性 conn.setRequestProperty("",""); 对于不同的 URL,我有不同的 header 。所以,它在我的项目中没有修复。 我需
这里的代码是一个普通的 Java 应用程序,而不是 android 应用程序,它被设计为将 C2DM 消息发送到具有 YOUR_REGISTRATION_STRING 的设备作为具有 auth_key
我在尝试按范围读取远程文件时遇到困难。 根据以下跟踪声音,setRequestProperty 没有执行其工作(InputStream 长度对我来说是不行的,除了一个..第一个???)? Task R
我查看了 android studio 中 URLConnection.setRequestProperty() 的源代码,它似乎没有设置任何内容: public void setRequestPro
我创建了一个类,我正在创建一个 HttpURLConnection对象并将该对象传递给另一个方法,如果它满足以下条件: 在这门课中,我通过了 username , password和 senderId
代码如下: String Surl = "http://mysite.com/somefile"; String charset = "UTF-8"; query = String.format("p
我正在尝试将 Java 应用程序转换为 C++,我正在为我的请求使用 cURL。下面是java代码;我想知道如何复制 connection.setRequestProperty() 方法。 conne
我有一个问题。当我尝试这样做时 connection.setRequestProperty("Sample", "Sample data \n"); 我得到 java.lang.IllegalArgu
HttpURLConnection con = null; Response response = new Response(); String TAG = "Http
我收到 java.lang.IllegalStateException: java.lang.IllegalStateException: Cannot set request property af
我是一名优秀的程序员,十分优秀!