在尝试维基百科查询时,CURLPP 400错误请求
CURLPP 400 Bad Request when trying a wikipedia query
我想通过以下URL提取维基百科页面的摘要:
https://en.wikipedia.org/w/api.php?format=json&action=query&prop=extracts&exintro=&explaintext=&titles=Stack%20Overflow
我也在使用CURLPP库来实现这个目标:
#include <curlpp/cURLpp.hpp>
#include <curlpp/Easy.hpp>
#include <curlpp/Options.hpp>
#include <curlpp/Exception.hpp>
#include <sstream>
#include <fstream>
#include <iostream>
using namespace std;
int main()
{
string query = "Aldous Huxley";
curlpp::Cleanup myCleanup;
std::ostringstream os;
string url = "https://en.wikipedia.org/w/api.php?format=xml&action=query&prop=extracts&exintro=&explaintext=&titles=";
os << curlpp::options::Url(std::string( url + query));
string asAskedInQuestion = os.str();
cout << asAskedInQuestion << endl;
return 0;
}
<标题> 输出
每次我尝试查询Aldous Huxley
时,我得到以下错误:
<html>
<head><title>400 Bad Request</title></head>
<body bgcolor="white">
<center><h1>400 Bad Request</h1></center>
<hr><center>nginx/1.9.4</center>
</body>
</html>
其他查询是否正常。为什么会出现这个错误?例如,当我尝试无政府主义时,我得到以下输出:
<api batchcomplete="">
<query>
<pages>
<page _idx="12" pageid="12" ns="0" title="Anarchism">
<extract xml:space="preserve">
Anarchism is a political philosophy that advocates stateless societies often defined as self-governed voluntary institutions, but that several authors have defined as more specific institutions based on non-hierarchical free associations. Anarchism holds the state to be undesirable, unnecessary, or harmful. While anti-statism is central, anarchism entails opposing authority or hierarchical organisation in the conduct of human relations, including, but not limited to, the state system. As an anti-dogmatic philosophy, anarchism draws on many currents of thought and strategy. Anarchism does not offer a fixed body of doctrine from a single particular world view, instead fluxing and flowing as a philosophy. There are many types and traditions of anarchism, not all of which are mutually exclusive. Anarchist schools of thought can differ fundamentally, supporting anything from extreme individualism to complete collectivism. Strains of anarchism have often been divided into the categories of social and individualist anarchism or similar dual classifications. Anarchism is usually considered a radical left-wing ideology, and much of anarchist economics and anarchist legal philosophy reflect anti-authoritarian interpretations of communism, collectivism, syndicalism, mutualism, or participatory economics.
</extract>
</page>
</pages>
</query>
</api>
标题>需要对查询字符串进行url编码。如使用。
string query = "Aldous%20Huxley";
相关文章:
- Mongodb c++驱动程序:如何查询元素的数组
- 查询SQLite数据库中的日期
- 如何使用curlpp通过POST方法上传文件和json数据
- 如何在ArangoDb AQL查询中指定数据库
- Qt SQLite没有查询或参数计数不匹配
- 如何使用c++在VS 2019上运行SQL查询
- 从返回的顶点缓冲区查询顶点结构
- 以非特权用户身份查询 NTFS 特殊文件的元数据?
- C/C++ - 查询平台相关的换行符(用于内存映射文件)
- 查询 NFS 上的提升进程间::file_lock
- Qt JSON – 从子项查询
- 在 c++ 中解决段树以外的范围查询的有效方法是什么?
- 无法从 Win10 中的 IDirectDraw7 查询 IDirect3D7
- 如何查询以确定我的 MacOS/X 应用程序是否处于应用程序午睡模式?
- 在子数组中查找多个查询的不同(唯一)值的数量
- DNS 查询格式标头结构中的小字节序问题
- QSql查询行受影响的结果
- C++库相关查询
- 优化使用 C++ 查询 SQLite DB 中超过 5000 万条数据记录的方式
- 在尝试维基百科查询时,CURLPP 400错误请求