Table of Contents
Use http protocol to post comments on blog posts,
Home Backend Development PHP Tutorial Use http protocol to publish blog post comments, _PHP tutorial

Use http protocol to publish blog post comments, _PHP tutorial

Jul 13, 2016 am 09:45 AM
http use protocol Blog Garden release Comment

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. Use http protocol to publish blog post comments, _PHP tutorialpublic 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:

Use http protocol to publish blog post comments, _PHP tutorial 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';
Copy after login

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.

www.bkjia.comtruehttp: //www.bkjia.com/PHPjc/1041591.htmlTechArticleUse http protocol to publish blog post comments. This blog post undertakes "php uses socket to send GET and POST requests". It requires Using the Http class encapsulated above, consider how to use php scripts to blog...
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn

Hot AI Tools

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Undress AI Tool

Undress AI Tool

Undress images for free

Clothoff.io

Clothoff.io

AI clothes remover

AI Hentai Generator

AI Hentai Generator

Generate AI Hentai for free.

Hot Article

R.E.P.O. Energy Crystals Explained and What They Do (Yellow Crystal)
1 months ago By 尊渡假赌尊渡假赌尊渡假赌
R.E.P.O. Best Graphic Settings
1 months ago By 尊渡假赌尊渡假赌尊渡假赌
Will R.E.P.O. Have Crossplay?
1 months ago By 尊渡假赌尊渡假赌尊渡假赌

Hot Tools

Notepad++7.3.1

Notepad++7.3.1

Easy-to-use and free code editor

SublimeText3 Chinese version

SublimeText3 Chinese version

Chinese version, very easy to use

Zend Studio 13.0.1

Zend Studio 13.0.1

Powerful PHP integrated development environment

Dreamweaver CS6

Dreamweaver CS6

Visual web development tools

SublimeText3 Mac version

SublimeText3 Mac version

God-level code editing software (SublimeText3)

How to publish works on Xiaohongshu How to publish articles and pictures on Xiaohongshu How to publish works on Xiaohongshu How to publish articles and pictures on Xiaohongshu Mar 22, 2024 pm 09:21 PM

You can view various contents on Xiaohongshu, which can provide you with various help and help you discover a better life. If you have anything you want to share, you can post it here so that everyone can take a look. , and at the same time, it can bring you profits. It is very cost-effective. If you don’t know how to publish your works here, you can check out the tutorial. You can use this software every day and publish various contents to help everyone use it better. Don’t miss it if you need it! 1. Open Xiaohongshu and click the plus icon below. 2. There are [Video] [Picture] [Live Picture] options here; select the content you want to publish and click to check. 3. Select [Next] on the content editing page. 4. Enter the text content you want to publish and click [Publish Pen]

How do I delete my comments on TikTok? How can others find out my comments on TikTok? How do I delete my comments on TikTok? How can others find out my comments on TikTok? Mar 21, 2024 pm 10:41 PM

People enjoy posting videos, browsing videos, commenting and interacting on Douyin. But in the comment interaction, sometimes we may make some inappropriate remarks or make mistakes and want to delete these comments. So how to delete my own comments on Douyin? 1. How to delete my comments on Douyin? 1. Log in to Douyin App and find the video with the comment you want to delete. 2. At the bottom of the video page, find a list of all comments. 3. Find your comment, click the heart icon (like) on the right side of the comment, then click the delete icon (trash can) to confirm deletion. 4. If you @ other people in the comment, you will receive a prompt when deleting the comment: &quot;After deleting this comment, the person @ will not receive the notification.&quot; If you want the person @ to receive the notification, you can Cancel @ first,

Why is Xiaohongshu's own comment at the bottom? How to modify a comment on Xiaohongshu? Why is Xiaohongshu's own comment at the bottom? How to modify a comment on Xiaohongshu? Mar 21, 2024 pm 10:46 PM

Xiaohongshu is a popular social e-commerce platform where users can share shopping tips, recommend products and exchange shopping experiences. Some users found that comments they posted on Xiaohongshu were always displayed at the bottom, which confused them. This article will explore why Xiaohongshu’s comments arrangement causes user comments to appear at the bottom, and introduce how to modify the position of comments on Xiaohongshu. 1. Why are Xiaohongshu’s own comments at the bottom? The display order of comments on Xiaohongshu is usually based on the chronological order of the comments. If your comment is posted after another user has commented, it will appear at the bottom. This is Xiaohongshu’s default comment sorting method, which is designed to maintain order and clarity in the comment area. Xiaohongshu may based on the content of the comments

Why can't pictures be displayed in Xiaohongshu comments? Why is the Xiaohongshu IP address not updated? Why can't pictures be displayed in Xiaohongshu comments? Why is the Xiaohongshu IP address not updated? Mar 21, 2024 pm 09:00 PM

Xiaohongshu is a popular social e-commerce platform where users can share their shopping experiences and recommend products. Some users reported that they were troubled by the fact that the images they uploaded in their comments were not displayed properly. This article will help you find out why images in Xiaohongshu comments cannot be displayed and provide solutions. 1. Why can’t pictures be displayed in Xiaohongshu comments? Image formats may not be supported: Xiaohongshu’s comment function only supports limited image formats. If the image format you upload is not supported, the image may not be displayed. It is recommended that you try other formats, such as JPG, PNG, etc. The size of images uploaded in comments may be limited by Xiaohongshu. If the size of your image is too large, it may not be displayed properly. It is recommended that you try pressing

How to publish Xiaohongshu video works? What should I pay attention to when posting videos? How to publish Xiaohongshu video works? What should I pay attention to when posting videos? Mar 23, 2024 pm 08:50 PM

With the rise of short video platforms, Xiaohongshu has become a platform for many people to share their lives, express themselves, and gain traffic. On this platform, publishing video works is a very popular way of interaction. So, how to publish Xiaohongshu video works? 1. How to publish Xiaohongshu video works? First, make sure you have a video content ready to share. You can use your mobile phone or other camera equipment to shoot, but you need to pay attention to the image quality and sound clarity. 2. Edit the video: In order to make the work more attractive, you can edit the video. You can use professional video editing software, such as Douyin, Kuaishou, etc., to add filters, music, subtitles and other elements. 3. Choose a cover: The cover is the key to attracting users to click. Choose a clear and interesting picture as the cover to attract users to click on it.

How to pin comments to the top of Xiaohongshu on the computer? Where are the private messages on the computer? How to pin comments to the top of Xiaohongshu on the computer? Where are the private messages on the computer? Mar 28, 2024 pm 12:36 PM

On Xiaohongshu, users can browse a variety of beauty, fashion, travel and other content, while also expressing their own opinions and comments. Some users encountered the problem of how to pin comments when using the Xiaohongshu computer version. 1. How to pin comments to the top of Xiaohongshu on the computer? 1. Open the computer version of Xiaohongshu and enter the post or update you want to comment on. 2. In the comment area, find the comment you want to pin. 3. Click on the comment and you will see a "Pin" button. 4. Click the "Pin" button, and the comment will appear at the top of the comment area and become a pinned comment. It should be noted that the Xiaohongshu computer version currently only supports pinning your own comments, and the pinning function is only valid in the comment area of ​​posts or updates, and cannot be pinned on topic pages or global comment areas. two,

Will I be reminded if my Xiaohongshu comment is deleted by the blogger? What should I do if my comments in Xiaohongshu are deleted? Will I be reminded if my Xiaohongshu comment is deleted by the blogger? What should I do if my comments in Xiaohongshu are deleted? Mar 28, 2024 am 11:46 AM

Xiaohongshu is a content-rich and interactive social platform where users can post and comment on various contents. Sometimes we may encounter situations where our comments are deleted by bloggers. So, will the blogger be reminded if a Xiaohongshu comment is deleted? What should we do if it is deleted? 1. Will the blogger be reminded if a Xiaohongshu comment is deleted? After a Xiaohongshu comment is deleted by the blogger, the system will provide a notification to the user. Users can check the notification in Xiaohongshu’s message center to learn why their comments were deleted. Users can also find their deleted comments in the comment record on their personal homepage and view the relevant situation. 2. What should I do if my comments in Xiaohongshu are deleted? 1. Stay calm: First of all, we need to stay calm and don’t panic or get angry. Bo

How can I retrieve someone else's deleted comment on Xiaohongshu? Will it be displayed if someone else's comment is deleted? How can I retrieve someone else's deleted comment on Xiaohongshu? Will it be displayed if someone else's comment is deleted? Mar 21, 2024 pm 10:46 PM

Xiaohongshu is a popular social e-commerce platform, and interactive comments between users are an indispensable method of communication on the platform. Occasionally, we may find that our comments have been deleted by others, which can be confusing. 1. How can I retrieve someone else’s deleted comments on Xiaohongshu? When you find that your comments have been deleted, you can first try to directly search for relevant posts or products on the platform to see if you can still find the comment. If the comment is still displayed after being deleted, it may have been deleted by the original post owner. At this time, you can try to contact the original post owner to ask the reason for deleting the comment and request to restore the comment. If a comment has been completely deleted and cannot be found on the original post, the chances of it being reinstated on the platform are relatively slim. You can try other ways

See all articles