簡體   English   中英

想要執行一個URL而不在PHP的瀏覽器中加載它

[英]want to execute a url without loading it in browser in php

目前,我在執行短信網關API時遇到問題。 他們要求我點擊一個網址,該網址是http://bulksmsgateway.in/sendmessage.php?user = ........&password = .......&mobile = ....... &消息= .......&發件人= .......類型= 3&

但是我必須這樣做,而不必在瀏覽器中加載此URL。 所以我用卷曲的方法。 以及出現400錯誤的請求錯誤的地方。這是具有PHP支持的Windows服務器。

我的代碼在這里-

$ ch = curl_init();

curl_setopt($ ch,CURLOPT_USERAGENT,'Mozilla / 4.0(compatible; MSIE 6.0; Windows NT 5.1; SV1; .NET CLR 1.0.3705; .NET CLR 1.1.4322)');

curl_setopt($ ch,CURLOPT_RETURNTRANSFER,1);

curl_setopt($ ch,CURLOPT_URL,$ url);

$ contents = curl_exec($ ch);

$ ee = curl_getinfo($ ch);

的print_r($ EE);

curl_close($ CH);

if($ contents){echo'sent'; 的print_r($內容); } else {echo'lost'; }

$ ee返回

Array([url] => http://bulksmsgateway.in/sendmessage.php?user=usrname&password=pwd&mobile=9126050xxx&message=感謝您通過FCI訂購。您的訂單將按時交付。您的訂單號為000198。請保留供將來參考。&sender = SUBANK&type = 3

[content_type] => text/html; charset=iso-8859-1
[http_code] => 400
[header_size] => 145
[request_size] => 411
[filetime] => -1
[ssl_verify_result] => 0
[redirect_count] => 0
[total_time] => 0.094
[namelookup_time] => 0
[connect_time] => 0.047
[pretransfer_time] => 0.047
[size_upload] => 0
[size_download] => 299
[speed_download] => 3180
[speed_upload] => 0
[download_content_length] => -1
[upload_content_length] => 0
[starttransfer_time] => 0.094
[redirect_time] => 0
[certinfo] => Array
    (
    )

[redirect_url] => 

我認為問題出在消息部分。 網址中郵件中的空間出現錯誤。因為沒有空間發送成功的郵件。 一個&nbsp也無法正常工作。請問在這方面,請幫我。

提前致謝。

您應該通過以下方式對消息查詢參數進行編碼:

$message = urlencode("Thanking you for ordering through FCI.Your Order will be delivered on time.Your order no is 000198.Please keep it for future");

這是帶有正確編碼的message參數,將作為GET參數發送:

感謝你+ +為訂購+到+ FCI.Your +訂單+會+被+提供+上+ time.Your +訂單+不+是+ 000198.Please +不斷+ IT +為+未來

http://www.technologyworkshops.net/tutorials-f39/curl-using-get-method-with-php-t135.html

function curlWithGetMethod($url, $data)
    {
    $fields_string = '';

    foreach($data as $key=>$value){
    $fields_string[]=$key.'='.urlencode($value).'&'; }
    $urlStringData = $url.'?'.implode('&',$fields_string);

    $ch = curl_init();

    curl_setopt($ch, CURLOPT_HEADER, 0);
    curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); 
    curl_setopt($ch, CURLOPT_CONNECTTIMEOUT,10); 
   curl_setopt($ch, CURLOPT_USERAGENT , "Mozilla/4.0 (compatible; MSIE 8.0; Windows NT 6.1)");
    curl_setopt($ch, CURLOPT_URL, $urlStringData ); 

    $return = curl_exec($ch);
    curl_close($ch);

    return $return;
}

$data = array('first_name' => 'myname', 'email' => 'example@example.com', 'phone' => '0123456789',  );
echo curlWithGetMethod(''http://www.technologyworkshops.net/', $data);

我已經用%20替換了空格,對我來說效果很好。謝謝您對大家的幫助...

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM