Use http protocol to post comments on blog posts,
This blog post undertakes "php uses socket to send GET and POST requests". To use the Http class encapsulated above, consider how Submit comments to Blog Park blog posts through php scripts.
Principle:
Before doing this, we must first understand that the essence of submitting comments to a blog post is to send a post request through the http protocol server. What do we need to do before posting a comment? Yes, you must log in. But logging in is another matter, which we won’t discuss here. After the user logs in, the server sets a cookie to the client. http is stateless. That is to say, after the client sends a request to the server, the server returns a response. One communication is completed. The server will not remember who just sent the request to it. Therefore, the client needs to send a request to the server with the cookie set by the server and inform the server of its identity, and the server generates a response based on the cookie. The principle is so simple, let’s take a look at our practical part.
Preparation:
In order to complete this test, I registered another blog account (DeanHuangChopper). After logging in to the blog park, open my blog (DeanChopper) and randomly open one of my blog posts, such as "Understanding Buffering Using the PHP OB Function" Mechanism" article (I use Firefox browser, the biggest advantage is that you can intuitively see what parameters are sent to the server), open the developer options, and prepare to record the process of sending comments. I just write a comment and leave a comment. This time the request is logged via developer options. public function post($body) {
$this->setLine('POST');
// Reset content-type
$this->setHeader('Content-Type:application/json; charset=UTF-8');
// Skip the setBody method
// $this->setBody($body);
$this->body[]=$body;
// Calculate content-length
$this->setHeader('Content-length: ' . strlen($this->body[0]));
$this->request();
return $this->response;
}
After re-modifying the Http class, we can complete the writing of the main code of this article. Although in theory, you only need to set the cookie value when setting the header information, it is best to send all the header information to increase the success rate.
Before sending a comment, take a look at the parameters sent:
Code part:
Finally is the main code of this article:
<?<span>php </span><span>require</span> "http.class.php"<span>; </span><span>$http</span>=<span>new</span> Http('http://www.cnblogs.com/mvc/PostComment/Add.aspx'<span>); </span>//设置头信息 <span>$http</span>->setHeader('Accept-Language:zh-CN,zh;q=0.8,en-US;q=0.5,en;q=0.3'<span>); </span><span>$http</span>->setHeader('Accept-Language:zh-CN,zh;q=0.8,en-US;q=0.5,en;q=0.3'<span>); </span><span>$http</span>->setHeader('Accept-Encoding:gzip, deflate'<span>); </span><span>$http</span>->setHeader('X-Requested-With:XMLHttpRequest'<span>); </span><span>$http</span>->setHeader('Referer:http://www.cnblogs.com/DeanChopper/p/4688667.html'<span>); </span><span>$http</span>->setHeader('Cookie:_ga=GA1.2.1359064105.1438444082; __gads=ID=e0c32fd6db6e2a6d:T=1438443900:S=ALNI_Mb6AAflcBD6gcdHgeE3IqVDJYnnjA; .CNBlogsCookie=C8013C91E54C151DEDA30E2C1E842982338C9054A8BB8639AC2DAB7578445BF1DF5BC49D39D8BE5FDAC33541CE4E4FA386CFD3F946EA1D79D1E34809A4CCBD7488A15641AEF685A6258CF3F03597BCAF50049F8C95A310076677598990FB2E4FB1E9671A; _5t_trace_sid=84a9ed0b086c2c127551cf911bec7b1d; _5t_trace_tms=1; _gat=1'<span>); </span><span>$http</span>->setHeader('Pragma:no-cache'<span>); </span><span>$http</span>->setHeader('Cache-Control:no-cache'<span>); <br />//设置请求体信息<br /></span><span>$msg</span>='{"blogApp":"DeanChopper","postId":4688667,"body":"测试内容","parentCommentId":0}'<span>; <br />//发送post请求<br /></span><span>$http</span>->post(<span>$msg</span><span>); </span><span>echo</span> 'OK';
The sending process may be a bit slow, please be patient.
Finally, I don’t mind bloggers using my blog post as a test for sending comments, but please pay attention to the wording.

Springboot内置tomcat禁止不安全HTTP方法1、在tomcat的web.xml中可以配置如下内容让tomcat禁止不安全的HTTP方法/*PUTDELETEHEADOPTIONSTRACEBASIC2、Springboot使用内置tomcat没有web.xml配置文件,可以通过以下配置进行,简单来说就是要注入到Spring容器中@ConfigurationpublicclassTomcatConfig{@BeanpublicEmbeddedServletContainerFacto

1.HttpURLConnection使用JDK原生提供的net,无需其他jar包,代码如下:importcom.alibaba.fastjson.JSON;importjava.io.BufferedReader;importjava.io.InputStream;importjava.io.InputStreamReader;importjava.io.OutputStream;importjava.net.HttpURLConnection;

如何利用GitLab进行项目文档管理一、背景介绍在软件开发过程中,项目文档是非常重要的资料,不仅能够帮助开发团队了解项目的需求和设计,还能提供给测试团队和客户参考。为了方便项目文档的版本控制和团队协作,我们可以利用GitLab来进行项目文档管理。GitLab是一个基于Git的版本控制系统,除了支持代码管理,还可以管理项目文档。二、GitLab环境搭建首先,我

一、前言#ssl写在443端口后面。这样http和https的链接都可以用listen443sslhttp2default_server;server_namechat.chengxinsong.cn;#hsts的合理使用,max-age表明hsts在浏览器中的缓存时间,includesubdomainscam参数指定应该在所有子域上启用hsts,preload参数表示预加载,通过strict-transport-security:max-age=0将缓存设置为0可以撤销hstsadd_head

httpkeepalive在http早期,每个http请求都要求打开一个tpcsocket连接,并且使用一次之后就断开这个tcp连接。使用keep-alive可以改善这种状态,即在一次tcp连接中可以持续发送多份数据而不会断开连接。通过使用keep-alive机制,可以减少tcp连接建立次数,也意味着可以减少time_wait状态连接,以此提高性能和提高httpd服务器的吞吐率(更少的tcp连接意味着更少的系统内核调用,socket的accept()和close()调用)。但是,keep-ali

一、urllib概述:urllib是Python中请求url连接的官方标准库,就是你安装了python,这个库就已经可以直接使用了,基本上涵盖了基础的网络请求功能。在Python2中主要为urllib和urllib2,在Python3中整合成了urllib。Python3.x中将urllib2合并到了urllib,之后此包分成了以下四个模块:urllib.request:它是最基本的http请求模块,用来模拟发送请求urllib.error:异常处理模块,如果出现错误可以捕获这些异常urllib

抖音作为一个全球知名的短视频社交平台,靠着其独特的个性化推荐算法赢得了广大用户的青睐。本文将深入研究抖音视频推荐的价值和原理,帮助读者更好地了解和充分利用这一功能。一、什么是抖音推荐视频抖音推荐视频是根据用户的兴趣和行为习惯,利用智能推荐算法为用户筛选和推送个性化视频内容。抖音平台通过分析用户的观看历史、点赞和评论行为、分享记录等数据,从庞大的视频库中精选出最符合用户口味的视频进行推荐。这种个性化推荐系统不仅提高了用户体验,也帮助用户发现更多符合其喜好的视频内容,从而增强用户黏性和留存率。在这个

被动检查对于被动健康检查,nginx和nginxplus会在事件发生时对其进行监控,并尝试恢复失败的连接。如果仍然无法恢复正常,nginx开源版和nginxplus会将服务器标记为不可用,并暂时停止向其发送请求,直到它再次标记为活动状态。上游服务器标记为不可用的条件是为每个上游服务器定义的,其中包含块中server指令的参数upstream:fail_timeout-设置服务器标记为不可用时必须进行多次失败尝试的时间,以及服务器标记为不可用的时间(默认为10秒)。max_fails-设置在fai


Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

AI Hentai Generator
Generate AI Hentai for free.

Hot Article

Hot Tools

Zend Studio 13.0.1
Powerful PHP integrated development environment

Notepad++7.3.1
Easy-to-use and free code editor

Atom editor mac version download
The most popular open source editor

SAP NetWeaver Server Adapter for Eclipse
Integrate Eclipse with SAP NetWeaver application server.

MinGW - Minimalist GNU for Windows
This project is in the process of being migrated to osdn.net/projects/mingw, you can continue to follow us there. MinGW: A native Windows port of the GNU Compiler Collection (GCC), freely distributable import libraries and header files for building native Windows applications; includes extensions to the MSVC runtime to support C99 functionality. All MinGW software can run on 64-bit Windows platforms.
