- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我正在尝试通过套接字编程和 C++ 脚本访问维基百科页面。我可以访问服务器,但收到 404 错误,通知我请求的 URL 不存在。只需在浏览器中输入相同的 URL 即可。
这是网址:http://en.wikipedia.org/wiki/Hypertext_Transfer_Protocol
这是 C++ 脚本:
#include <iostream>
#include <sys/socket.h>
#include <resolv.h>
#include <arpa/inet.h>
#include <unistd.h>
#include <cstring>
using namespace std;
int main()
{
int s, error;
char length[10];
length[0]=0;
struct sockaddr_in addr;
if((s = socket(AF_INET,SOCK_STREAM,0))<0)
{
cout<<"Error 01: creating socket failed!\n";
close(s);
return 1;
}
addr.sin_family = AF_INET;
addr.sin_port = htons(80);
inet_aton("204.27.61.92",&addr.sin_addr);
error = connect(s,(sockaddr*)&addr,sizeof(addr));
if(error!=0)
{
cout<<"Error 02: conecting to server failed!\n";
close(s);
return 1;
}
char msg[]="GET /wiki/Hypertext_Transfer_Protocol HTTP/1.1\nHOST: en.wikipedia.org\n\n"
int leng = send(s, msg, sizeof(msg), 0);
if(leng == -1)
cout<<"There is a problem!"<<endl;
send(s,msg,sizeof(msg),0);
char answ[1024];
ssize_t len;
while((len = recv(s, answ, 1024, 0)) > 0)
{
cout.write(answ, len);
}
cout << endl;
if(len < 0)
{
cout<<"Error!"<<endl;
}
close(s);
return 0;
}
该脚本总体上运行良好。交换线路
char msg[]="GET /wiki/Hypertext_Transfer_Protocol HTTP/1.1\nHOST: en.wikipedia.org\n\n";
与
char msg[] = "GET /beej/inet_ntoaman.html http/1.1\nHOST: retran.com\n\n";
无错误地检索请求的网站。我在这里错过了什么?为什么该脚本不适用于维基百科?
谢谢
最佳答案
您可以通过尝试实现 HTTP 1.0 来使事情变得容易得多。
关于c++ - 对维基百科的 HTTP 请求,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36267819/
好吧,我看过一些帖子提到其他一些关于不使用 SP wiki 的帖子,因为它们很糟糕。 既然我们正在考虑在 SP 中创建 wiki,我需要知道为什么我们不应该让 6 名自动化开发人员来记录各种自动化流程
在 GitLab Wiki 部分,可以查看保存更改的历史记录。但是,当您单击提交链接时,它将显示该保存中存在的整个文件。有谁知道一种方法来区分提交以仅获取两个提交之间的差异? 这类似于它在 merge
我使用了 Wiki API 文档中的一些示例代码,但是当我输入搜索项时,没有任何反应。控制台中没有错误,什么也没有。如果我将 URL 输入到浏览器中,URL 本身就会起作用,所以我认为代码中的某些内容
我想在我的 wiki 中创建一个层次结构,如下所示: General FooPages Foo1 Foo2 Foo3 ODP Bar Baz 我想创建这些页
我正在尝试使用为 Python 制作的 Wikimapia 的 pymapia API,但无法理解如何正确使用它。 import pymapia as PyMapia a = PyMapia.PyMa
我正在开发适用于 iOS 的客户端应用程序,用于在 Mac OS X 服务器(Snow Leopard 和 Lion)上编辑内置的 Wiki/Blog。 看来我们可以使用 MetaWeblog 、At
我正在编写一些 URL 重写软件,我想从多个角度了解哪种 URL 方案更可取: 博客风格:my-chemistry-answer -- 为什么? -- (不可取,技术性) Wiki 风格:My_Che
我一直试图找到一种方法来在 Azure DevOps Wiki 中创建子页面的目录。我从其他 wiki 服务中找到了方法。 在 Confluence 中,他们有一个用于“ child 显示”的宏 我为
我是一名优秀的程序员,十分优秀!