search
HomePHP LibrariesOther librariesPHP class to send POST request
PHP class to send POST requestThe
<?php
class Request{
public static function post($url, $post_data = '', $timeout = 5){//curl
$ch = curl_init();
curl_setopt ($ch, CURLOPT_URL, $url);
curl_setopt ($ch, CURLOPT_POST, 1);
if($post_data != ''){
curl_setopt($ch, CURLOPT_POSTFIELDS, $post_data);
}
curl_setopt ($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt ($ch, CURLOPT_CONNECTTIMEOUT, $timeout);
curl_setopt($ch, CURLOPT_HEADER, false);
$file_contents = curl_exec($ch);
curl_close($ch);

Post() function is used to send non-PowerBuilder predefined event messages to the window. This window can be the window of the PowerBuilder application or the window of other applications. The Post() function places the sent message at the end of the specified window message queue and then returns it to the application. It does not wait for the execution of the corresponding event handler. This is different from the Send() function. The Send() function directly triggers the corresponding event of the specified window and returns to the calling application after executing the event handler. Therefore, we say that the Post() function uses an asynchronous method, and the Send() function uses a synchronous method. The parameter handle of the Post() function specifies the window handle for receiving the message. For the PowerBuilder window, the handle can be obtained using the Handle() function. For windows of other applications, you can call the system API function to find the window and get the handle of the corresponding window. If the application wants to post PowerBuilder defined events (including predefined events and user-defined events), then using the PostEvent() function is simple and convenient. When the application specifies a string in the long parameter position, the Post() function makes a copy of the string and then transmits the address of the copy to the specified window.


Disclaimer

All resources on this site are contributed by netizens or reprinted by major download sites. Please check the integrity of the software yourself! All resources on this site are for learning reference only. Please do not use them for commercial purposes. Otherwise, you will be responsible for all consequences! If there is any infringement, please contact us to delete it. Contact information: admin@php.cn

Related Article

How to send post request in phpHow to send post request in php

27Sep2019

There are three ways for PHP to send post requests. Post submission data can be implemented through curl, file_get_content, and fsocket.

PHP simulates post request to send file codePHP simulates post request to send file code

25Jul2016

PHP simulates post request to send file code

PHP simulates post request to send files_PHP tutorialPHP simulates post request to send files_PHP tutorial

13Jul2016

PHP simulates post request to send files. PHP simulates post requests to send files. Due to project needs, the local server needs to receive the data and then forward the data to another server, so it is necessary to use simulated post requests to send data.

What to do if PHP fails to send POST requestWhat to do if PHP fails to send POST request

13Jul2021

Solution to PHP failure to send POST request: first check the error through "echo curl_error($ch);"; then set https trust when requesting.

How to send post request with jqueryHow to send post request with jquery

02Apr2022

In jquery, you can use the "$.post()" method to send a post request. The function of this method is to use an HTTP POST request to load data from the server. The syntax is "$(selector).post(URL,data, which stipulates that when the request is successful function to be run, data type)".

How to send POST request using JSON formatHow to send POST request using JSON format

12Jun2018

This time I will show you how to use JSON format to send POST requests, and what are the precautions for using JSON format to send POST requests. The following is a practical case, let's take a look.

See all articles