>  기사  >  백엔드 개발  >  PHP 컬이 게시할 수 없으면 어떻게 해야 합니까?

PHP 컬이 게시할 수 없으면 어떻게 해야 합니까?

藏色散人
藏色散人원래의
2021-09-15 09:50:032166검색

PHP 컬이 게시할 수 없는 문제에 대한 해결 방법: 1. 해당 PHP 코드 파일을 엽니다. 2. "$post_data = "username=bob&key=12345";$response = http_req(...)"를 통해 데이터를 제출합니다.

PHP 컬이 게시할 수 없으면 어떻게 해야 합니까?

이 기사의 운영 환경: Windows 7 시스템, PHP 버전 7.1, DELL G3 컴퓨터

php 컬이 게시할 수 없으면 어떻게 해야 합니까?

php 컬 포스트가 데이터를 제출하지 못했습니다.

The 코드는 다음과 같습니다:

function http_req($http_type, $method, $url, $data)
{
    $ch = curl_init();
    if (strstr($http_type, 'https')) {
        curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
        curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 0);
    }

    if ($method == 'post') {
        curl_setopt($ch, CURLOPT_POST, 1);
        curl_setopt($ch, CURLOPT_POSTFIELDS, $data);
    } else {
        $url = $url . '?' . $data;
    }
    curl_setopt($ch, CURLOPT_URL, $url);
    curl_setopt($ch, CURLOPT_HEADER, 0);
    curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
    curl_setopt($ch, CURLOPT_TIMEOUT, 100000);//超时时间

    try {
        $ret = curl_exec($ch);
    } catch (Exception $e) {
        curl_close($ch);
        return json_encode(array('ret' => 0, 'msg' => 'failure'));
    }
    curl_close($ch);
    return $ret;
}
  //第一种提交方式在遇到post_data 中包含@等一些符号时会出现提交失败的情况
  $url = "http://localhost/web_services.php";
 $post_data = array ("username" => "bob","key" => "12345");
 $response = http_req('http', 'post', $url, $post_data );
 //第二种提交方式可以避免
 $url = "http://localhost/web_services.php";
 $post_data = "username=bob&key=12345";
 $response = http_req('http', 'post', $url, $post_data );

   

추천 학습: "PHP 비디오 튜토리얼"

<br>

위 내용은 PHP 컬이 게시할 수 없으면 어떻게 해야 합니까?의 상세 내용입니다. 자세한 내용은 PHP 중국어 웹사이트의 기타 관련 기사를 참조하세요!

성명:
본 글의 내용은 네티즌들의 자발적인 기여로 작성되었으며, 저작권은 원저작자에게 있습니다. 본 사이트는 이에 상응하는 법적 책임을 지지 않습니다. 표절이나 침해가 의심되는 콘텐츠를 발견한 경우 admin@php.cn으로 문의하세요.