2016-07-26 45 views
0

我使用Laravel 5.2和我剛創建簡單的類,我創建Web請求接收JSON文件。更改&到&在php類

因此類的部分看起來像:

public function request(){ 
    $request = 'https://example.com/someotherthings/var='.$value1.'&var2='.$value2'; 
} 

對此我得到:

https://example.com/someotherthings/var=valueOfValue1&var2=valueOfValue2 

的問題是,要求是錯誤的,我也沒有得到回報響應。

+0

您是否嘗試過'urlencode'?這裏你有文檔:http://php.net/manual/es/function.urlencode.php – Mumpo

回答

0

刪除最後一個引號:

$request = 'https://example.com/someotherthings/var='.$value1.'&var2='.$value2'; 

變爲:

$request = 'https://example.com/someotherthings/var='.$value1.'&var2='.$value2; 

然後是安全編碼的網址:

$urlEncodedRequest = urlencode($request);